我有一个带有按钮的UIView
,需要在将视图添加到self.view
时设置焦点在按钮上,但是当视图被添加时,我不知道为什么按钮没有获得焦点!
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator: (UIFocusAnimationCoordinator *)coordinator {
if (context.nextFocusedView == backButton) {
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.40 initialSpringVelocity:.60 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
context.nextFocusedView.transform = CGAffineTransformMakeScale(1.5, 1.5);
context.nextFocusedView.layer.shadowOffset = CGSizeMake(0, 10);
context.nextFocusedView.layer.shadowOpacity = 1;
context.nextFocusedView.layer.shadowRadius = 15;
context.nextFocusedView.layer.shadowColor = [UIColor redColor].CGColor;
context.nextFocusedView.layer.shadowOpacity = 1;
} completion:nil];
}
}
我还尝试了其他属性:
- (void)openView {
[backButton preferredFocusedView];
[backButton canBecomeFocused];
[backButton setNeedsFocusUpdate];
[self.view addSubView:customView];
}
- (UIView *)preferredFocusedView {
return [backButton preferredFocusedView];
}
但是这些都没有起作用!