tvOS: Focus not moving correctly

后端 未结 2 1728
耶瑟儿~
耶瑟儿~ 2021-01-14 19:12

I have a UIView with two buttons on it. In the MyView class I have this code:

-(BOOL) canBecomeFocused {
    return YES;
}

-(NSArray

        
2条回答
  •  天命终不由人
    2021-01-14 19:50

    You can override the preferredFocusEnviromnets with the following logic:

    -(NSArray> *)preferredFocusEnvironments {
        if (condition) {
            return @[_editButton];
        }
        else {
            return @[_addButton];
        }
    }
    

    After setting it, you can call

    [_myView setNeedsFocusUpdate];
    [_myView updateFocusIfNeeded];
    

    The condition could be BOOL condition = tableViewController.editing; or sg like that.

    If that now works, you can call it with a delay (0.1 sec or so).

提交回复
热议问题