繁体   English   中英

覆盖在Category中定义的应该AutorotateToInterfaceOrientation

[英]Override shouldAutorotateToInterfaceOrientation defined in Category

我定义了以下类别以允许TabBarController方向

@implementation UITabBarController (MyApp) 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end

现在有几个viewcontroller ,我不想允许使用横向模式。 因为我使用了类别,所以将忽略viewcontroller的方法。 有办法解决吗?

(我知道您可以将UITabBarController子类化,但是Apple自己不建议这样做)。

您可以像这样询问您类别中的当前视图控制器:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return [[self selectedViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

您可能需要根据需要实现更多的逻辑。 同样,在您的情况下,子类比自定义类别更好,全局覆盖的内容在将来某个时候可能会中断。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM