iPhone - 只允许一个视图控制器的横向方向
我有一个基于导航的应用程序,我只希望其中一个视图控制器支持横向。对于该视图控制器(vc1),在shouldAutorotate中,我将返回YES用于所有方向,而在其他控制器中,我只返回YES仅适用于肖像模式iPhone - 只允许一个视图控制器的横向方向
但即使如此,如果设备处于横向模式,我会转到下一个屏幕从vc1开始,下一个屏幕也会以横向模式旋转。我认为如果我只为肖像模式返回YES,屏幕只能以肖像模式显示。
这是预期的行为?我如何实现我所寻找的?
谢谢。
如果您使用shouldAutorotateToInterfaceOrientation UIViewController的方法,则不能仅支持其中一个视图控制器的横向方向。
您只有两个选择,无论所有viewcontrollers是否支持横向或者viewcontrollers都不支持它。
如果您只想支持一种格局,您需要检测设备旋转并手动旋转视图控制器中的视图。
您可以使用通知检测设备旋转。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
然后,当检测设备旋转,你可以旋转你的看法。
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[notification object] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
[xxxView setTransform:CGAffineTransformMakeRotation(M_PI/2.0)];
} else if (orientation == UIDeviceOrientationLandscapeRight) {
[xxxView setTransform:CGAffineTransformMakeRotation(M_PI/-2.0)];
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
[xxxView setTransform:CGAffineTransformMakeRotation(M_PI)];
} else if (orientation == UIDeviceOrientationPortrait) {
[xxxView setTransform:CGAffineTransformMakeRotation(0.0)];
}
}
我也有这种情况,当我需要所有视图控制器在portait模式下,但其中一个也可以旋转到横向模式。而这个视图控制器有导航栏。
为此,我创建了第二个窗口,在我的情况下是摄像头视图控制器。而当我需要显示相机视图控制器时,我会显示相机窗口,并在需要推送另一个视图控制器时隐藏。
而且您还需要将此代码添加到AppDelegate。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (window == self.cameraWindow)
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
正如我制定了我的程序,我建议你使用这个solution.By在shouldAutorotateToInterfaceOrientation方法取向型使用某些情况下,我们可以解决this.Just该链接的尝试会帮助你。
可能重复:http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation – 2010-01-27 04:17:36
我不想设置方向。我只想要其中一个视图不响应方向更改。 – lostInTransit 2010-01-27 04:27:32
类似的问题也在http://stackoverflow.com/questions/2041884/problem-with-uiviewcontroller-orientation/2042040#2042040但没有答案添加。 – 2010-01-27 05:08:25