Rya*_*yan 17 rotation uitabbarcontroller orientation uinavigationcontroller ios6
我有一个iPhone应用程序我正在更新到iOS 6有旋转问题.我有UITabBarController
16岁UINavigationCotrollers
.大多数子视图可以在纵向或横向上工作,但其中一些只是纵向.对于iOS 6,它们不应该旋转.
我尝试将supportedInterfaceOrienations
tabBarController 子类化为返回当前navigationController的选定viewController:
- (NSUInteger)supportedInterfaceOrientations{
UINavigationController *navController = (UINavigationController *)self.selectedViewController;
return [navController.visibleViewController supportedInterfaceOrientations];
}
Run Code Online (Sandbox Code Playgroud)
这让我更接近.视图控制器在可见时不会旋转到位置,但如果我处于横向和切换选项卡中,即使不支持,新选项卡也将处于横向状态.
理想情况下,应用程序仅在当前可见视图控制器的支持方向上.有任何想法吗?
Dea*_*ids 58
您UITabBarController
重写这些方法的子类:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
您UINavigationController
重写这些方法的子类:
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
然后在您不想旋转的viewControllers中实现这些方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
对于您想要旋转的viewControllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
您的tabbarController应添加为应用程序窗口的RootviewController.如果您打算支持默认方向,除iPhone上的所有内容都是默认方式,那么您无需执行任何其他操作.如果您想要支持颠倒或者如果您不想支持其他方向,则需要在app delegate和/或info.plist中设置适当的值.
我有一个问题,导航堆栈中的一些View控制器支持所有方向,一些只有肖像,但是UINavigationController
返回所有应用程序支持的方向,这个小黑客帮助了我.我不确定这是预期的行为还是什么
@implementation UINavigationController (iOS6OrientationFix)
-(NSUInteger) supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
@end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16805 次 |
最近记录: |