How can I force focus to change to a specific view in tvOS?

后端 未结 6 2310
Happy的楠姐
Happy的楠姐 2021-02-19 15:51

I am implementing custom code to handle a click on the Menu button on the Siri Remote. How can I force focus to change to my custom menu when pressing the menu button?

6条回答
  •  既然无缘
    2021-02-19 16:42

    @elu5ion 's answer, but in objective-c first declare:

    @property (nonatomic) UIView *preferredView;
    

    Set these methods:

    -(void)setPreferredView:(UIView *)preferredView{
          if (preferredView != nil) {
             _preferredView = nil;
             UIFocusGuide *focusGuide = [[UIFocusGuide alloc]init];
             [self.view addLayoutGuide:focusGuide];
             focusGuide.preferredFocusedView = [self preferredFocusedView];
             [self setNeedsFocusUpdate];
             [self updateFocusIfNeeded];
        }
        _preferredView = preferredView;
     }
    
    
     - (UIView *)preferredFocusedView {
         if (_preferredView) {
              return _preferredView;
         }
         return self.view.preferredFocusedView;
    }
    

提交回复
热议问题