[英]How to change focus programmatically in tvOS
I am developing a tvOS app in swift. 我正在迅速开发一个tvOS应用程序。 I am using
UITabBarController
in the app. 我在应用程序中使用
UITabBarController
。 My requirement is to hide the tabbar automatic after 10 seconds and focus can move to AVPlayerViewController
inside the tabbar item. 我的要求是10秒后自动隐藏
AVPlayerViewController
,焦点可以移到AVPlayerViewController
栏项内的AVPlayerViewController
。 I tried to override preferredFocusedView
, but focus cannot move to AVPlayerViewController
. 我试图覆盖
preferredFocusedView
,但是焦点无法移至AVPlayerViewController
。
func updateFocus() {
self.playerController.view.hidden = false
self.playerController.view.alpha = 1.0
self.playerController.view.userInteractionEnabled = true
self.playerController.view.layer.zPosition = 1.0
self.preferredFocusedView
setNeedsFocusUpdate()
updateFocusIfNeeded()
}
override var preferredFocusedView: UIView? {
return self.playerController.view
}
Please suggest me how to move focus programmatically. 请建议我如何以编程方式转移焦点。
Issue is focus
is not in viewController
at that time instead focus is in tabBarController
, so what I will suggest you is do something like this, Create a TabBarController
subClass and set class of your tabController in story board to that class, and then in tabBarController
subClass do something like this. 问题
focus
不在viewController
当时转而集中在tabBarController
,所以我会建议你是做这样的事情,创建一个TabBarController
子类,并设置类故事板的tabController的那类,然后在tabBarController
子类做这样的事情。
#import "TabBarViewController.h"
@interface TabBarViewController ()
@end
@implementation TabBarViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.alpha = 0;
// set alpha = 1 back again when you need.
}
- (UIView*)preferredFocusedView
{
// you can also add some if else here
return [self.selectedViewController preferredFocusedView];// or you can do self.selectedViewController.view if that view is focusable
}
@end
My selected view controller here is FirstViewController which look like this and its working fine. 我在这里选择的视图控制器是FirstViewController,它看起来像这样,并且工作正常。
#import "FirstViewController.h"
@interface FirstViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button;
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (UIView*)preferredFocusedView
{
return _button;// return view which you want to make focus able
}
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.