Objective c 设置焦点顺序

Objective c 设置焦点顺序,objective-c,xcode,uibutton,tvos,Objective C,Xcode,Uibutton,Tvos,我现在有3个叫做MenuButton的对象,它是UIButton的子对象。它们在一行中定义,如图所示 我已经在我的菜单按钮-didUpdateFocusInText:withAnimationCoordinator方法中定义了突出显示状态: - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)c

我现在有3个叫做MenuButton的对象,它是UIButton的子对象。它们在一行中定义,如图所示

我已经在我的菜单按钮-didUpdateFocusInText:withAnimationCoordinator方法中定义了突出显示状态:

- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context
       withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
    if (context.nextFocusedView == self)
    {
        [self setTitleColor:[UIColor whiteColor]
                   forState:UIControlStateNormal];

    }
    else if (context.previouslyFocusedView == self)
    {
        [self setTitleColor:[UIColor colorWithRed:25.0/255.0
                                              green:23.0/255.0
                                               blue:16.0/255.0
                                              alpha:1.0]
                     forState:UIControlStateNormal];
    }

}
我还通过以下方式在MenuButton对象中设置了canBecomeFocused:

- (BOOL)canBecomeFocused
{
    return YES;
}
我已使用以下方法设置初始焦点按钮:

[_camerasButton setNeedsFocusUpdate]
当我在模拟器遥控器上滑动时,我无法让它专注于交付

有人能解释一下我如何使用UIFocusGuide在Objective-C中正确实现这一点吗

更新1 根据JustinVoss对第一条评论的建议,我设置了断点,并在调试控制台上做了一个“为什么此视图不可聚焦”的分析。收到此提示:

(lldb) po [(UIView*)0x7ff68054f7c0 _whyIsThisViewNotFocusable] 
ISSUE: This view may not be focusable because other views or focus guides are occluding it.
我正在定义菜单按钮框架,如图所示:

MenuButton *deliveriesButton = [MenuButton buttonWithType:UIButtonTypeCustom];
    [deliveriesButton setTitle:@"Deliveries" forState:UIControlStateNormal];
    [deliveriesButton setTitleColor:[UIColor colorWithRed:25.0/255.0
                                                 green:23.0/255.0
                                                  blue:16.0/255.0
                                                 alpha:1.0]
                        forState:UIControlStateNormal];
    [deliveriesButton.titleLabel setFont:[Constants lightFontOfSize:39]];
    [deliveriesButton sizeToFit];

    deliveriesButton.center = CGPointMake(viewWidth/2,
                                       menuBarHeight / 2);

    [self.view addSubview:deliveriesButton];
    _deliveriesButton = deliveriesButton;

使用Justin Voss在上述评论中引用的解决方案,我在我的UIViewController中浏览了UIViews并设置:

view.userInteractionEnabled = NO;
在我不需要选择的任何视图上(包括背景UIImageView对象)。这就解决了问题


希望这对其他人有所帮助

您尝试过各种焦点调试技术吗?如果焦点不移动的原因是因为两个视图的帧没有很好地对齐,那么焦点指南会有所帮助,但这似乎不是您的问题。您可能需要尝试_whythis views notfocusable方法来找出“交付”无法聚焦的原因。(详见我的回答:)嘿,贾斯汀,谢谢你的回答。我设置了一个断点,在注销按钮上做了一个_为什么此视图不可聚焦,并收到了以下提示:“问题:此视图可能不可聚焦,因为其他视图或聚焦向导正在阻挡它。”。有什么建议吗?必须有另一个视图(可能是透明的)位于按钮顶部,这会导致焦点引擎无法“看到”按钮。检查视图层次结构,查看该区域中是否有任何东西可能会阻止您的按钮。