Gry*_*ack 3 iphone xcode portrait orientation screen-rotation
我遇到设备轮换问题.除了一个视图,我显示公司启动画面,我想将所有剩余的应用程序视图锁定到纵向显示.在项目设置中,支持的方向是Portrait和LandscapeLeft.在"公司飞溅"中它工作正常,无论我如何旋转设备,视图旋转都锁定在LandscapeLeft中.在我将设备向左旋转的所有其他视图中,视图会改变而不是保持纵向显示.这些方法甚至没有开火?如果我从项目中支持的方向中删除横向,则会拧紧"公司启动"视图.我尝试改变shouldAutorotate回归NO,但这没有帮助.试图通过这里发布的建议,但这没有帮助.如果我将以下代码放入我的AppDelegate.m,一切都被锁定为纵向模式,并且"公司启动"在访问时崩溃.
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
除了一个屏幕外,无论设备如何旋转,如何将视图锁定为纵向模式?
**来自'公司飞溅'视图的方法.再次,应该是这样的工作.
-(NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
Run Code Online (Sandbox Code Playgroud)
**来自所有其他视图的方法,当我不希望它们旋转时,这些视图会旋转出来
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// IOS5 Only returning that it should rotate to potrait
return (interfaceOrientation == UIDeviceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
// forcing the rotate IOS6 Only
return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
// return number or enum IOS6 Only
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
我想也许可能是因为UITabBarController是根控制器而我在ViewController中呢?这些方法甚至没有开火?
将观察者添加到要旋转的视图的viewDidLoad方法,如下所示:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
Run Code Online (Sandbox Code Playgroud)
然后根据orientationChanged方法中的横向视图设置视图,如下所示:
- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
break;
case UIDeviceOrientationPortraitUpsideDown:
break;
case UIDeviceOrientationLandscapeLeft:
break;
case UIDeviceOrientationLandscapeRight:
break;
default:
break;
};
}
Run Code Online (Sandbox Code Playgroud)