Dar*_*ren 1 iphone cocoa-touch uiinterfaceorientation ios
我已经覆盖了我的UINavigationController来实现这些方法:
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
Run Code Online (Sandbox Code Playgroud)
现在从我的第一个视图,我在这里模态地呈现这个MSNavigationPaneViewController ,就像一个Facebook侧滑动标签栏控制器.
我需要在此处显示的1个视图控制器才能显示横向,而应用程序视图的其余部分仅为纵向.
所以在我的所有其他View控制器中,我添加了:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
在我想要的景观中我添加了:
- (BOOL)shouldAutorotate
{
return UIInterfaceOrientationMaskLandscape;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
Run Code Online (Sandbox Code Playgroud)
然而我的所有观点都在旋转
如果我shouldRotate
在这些其他视图上更改为NO,那么它们将保留在Portrait中,并且我想要成为Landscape的视图可以旋转,但是我无法让它自行旋转.此外,一旦旋转,如果我回到另一个视图,shouldRotate = NO;
然后它不能旋转回肖像.
我已经在这几个小时了,无法让它工作.
谢谢
编辑-----
我现在正在这一半工作,并开始一个新问题,让自动旋转在这里工作
看来你很困惑在shouldAutorotate中返回什么.使用以下代码作为示例.
由于iOS正在调用应用程序的shouldAutorotate来响应加速度计的事件,因此它已经知道新的方向; 如果你的应用回答"是",iOS可以根据支持的列表检查当前方向,并在没有你的应用查询当前方向的情况下做出决定.
// iOS 6
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
此外,您可以让显示模态视图控制器的视图控制器通知它旋转.使用:presentViewController:animated:completion:呈现视图控制器.presentModalViewController:animated:如果您正在使用它,则不推荐使用.
如果添加application:supportedInterfaceOrientationsForWindow:
,请务必遵循以下代码准则.该文档指出,如果您supportedInterfaceOrientations
在VC上实现它应该覆盖应用程序委托.但是,人们已经注意到它对于如何添加rootViewController
到主窗口有所不同.
使用:
window.rootViewController = viewController
Run Code Online (Sandbox Code Playgroud)
代替:
[window addSubview:viewController.view];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1830 次 |
最近记录: |