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

后端 未结 6 2306
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:38

    here is the objective C

    - (UIView *)preferredFocusedView
    {
        if (someCondition) {
          // this is if your menu is a tableview
            NSIndexPath *ip = [NSIndexPath indexPathForRow:2 inSection:0];
            UITableViewCell * cell = [self.categoryTableView cellForRowAtIndexPath:ip];
    
            return cell;
        }
    
        return self.view.preferredFocusedView;
    
    }
    

    in your viewDidLoad or view did appear do something like this:

        UIFocusGuide *focusGuide = [[UIFocusGuide alloc]init];
        focusGuide.preferredFocusedView = [self preferredFocusedView];
        [self.view addLayoutGuide:focusGuide];
    

    if you want to do it when it first launches

提交回复
热议问题