我目前有3个名为MenuButton的对象,它们是UIButton的子对象。它们如图所示连续定义。
我在我的MenuButton -didUpdateFocusInContext中定义了高亮状态: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对第一条评论的建议,我设置了断点并在调试控制台上做了一个_whyIsThisViewNotFocusable。收到这个提示:
(lldb) po [(UIView*)0x7ff68054f7c0 _whyIsThisViewNotFocusable]
ISSUE: This view may not be focusable because other views or focus guides are occluding it.
我正在定义我的MenuButton框架,如下所示:
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;
答案 0 :(得分:1)
在上面的评论中使用Justin Voss引用的解决方案,我在UIViewController中浏览了UIViews并设置:
view.userInteractionEnabled = NO;
在任何我不需要选择的视图上(包括后台UIImageView对象)。这解决了这个问题。
希望这有助于其他人