简体   繁体   English

视图不旋转

[英]View is not rotating

I am making a navigation based app and I need only portrait orientation except in a ZoomPictureViewController ( Zoom in, zoom out images) that supports all orientations. 我正在制作一个基于导航的应用程序,除了支持所有方向的ZoomPictureViewController (放大,缩小图像)外,我只需要纵向方向。

I am presenting ZoomPictureViewController and returning YE S in shouldAutorotateToInterfaceOrientation: 我正在展示ZoomPictureViewController并在ZoomPictureViewController返回YE S shouldAutorotateToInterfaceOrientation:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

But I get no rotation. 但是我没有轮换。 I know that shouldAutorotateToInterfaceOrientation , willRotateToInterfaceOrientation , RotateToInterfaceOrientation are only get called on the current/visible view controller but this is not happening in my case. 我知道shouldAutorotateToInterfaceOrientationwillRotateToInterfaceOrientationRotateToInterfaceOrientation只得到所谓的电流/可见视图控制器上,但这不是我的情况发生。 I have checked it via putting breakpoints and NSLog . 我已经通过放置断点和NSLog进行了检查。

Are you using any type of Navigation Controller or a Tab View Controller? 您正在使用任何类型的导航控制器或选项卡视图控制器吗? I've noticed that there are issues when rotating a UIView that's not the first or only view as a direct child of the main window. 我已经注意到,旋转不是主窗口的第一个或唯一视图的UIView时存在问题。

So if your UIView is part of a Navigation Controller or a Tab View Controller, you'll also need to override shouldAutoRotateToInterfaceOrientation on the Navigation Controller or Tab View Controller. 因此,如果您的UIView是导航控制器或选项卡视图控制器的一部分,则还需要覆盖导航控制器或选项卡视图控制器上的shouldAutoRotateToInterfaceOrientation

Also I here's an important gotcha in the Apple documentation that might explain the problem you are having. 另外,这也是Apple文档中的一个重要陷阱,可能会解释您遇到的问题。

Tab bar controllers support a portrait orientation by default and do not rotate to a landscape orientation unless all of the root view controllers support such an orientation. 选项卡栏控制器默认情况下支持纵向,除非所有的根视图控制器都支持横向,否则它们不会旋转为横向。 When a device orientation change occurs, the tab bar controller queries its array of view controllers. 当设备方向发生变化时,选项卡栏控制器将查询其视图控制器数组。 If any one of them does not support the orientation, the tab bar controller does not change its orientation. 如果其中任何一个都不支持方向,则标签栏控制器不会更改其方向。

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

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