无法将界面方向旋转为纵向倒置 [英] Cannot rotate interface orientation to portrait upside down

查看:127
本文介绍了无法将界面方向旋转为纵向倒置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone模拟器和iPhone 3GS(iOS 6)上,我都无法将方向设置为纵向颠倒。我只有一个ViewController。我在其中添加了此代码:

Both on iPhone simulator and iPhone 3GS (iOS 6) I cannot manage to set the orientation to portrait upside down. I have just one ViewController. I've added this code in it:

-(BOOL) shouldAutorotate{
 return YES; 
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
 return UIInterfaceOrientationPortraitUpsideDown;
}

- (NSUInteger)supportedInterfaceOrientations{
 return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
  if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
    return YES;
  }
 return NO;
}

我还将此添加到AppDelegate.m:

I also added this to AppDelegate.m:

-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

我还检查了plist文件,两个方向都存在。在我的故事板上,在Simulated Metrics Orientation设置为Inferred。我在applicationDidFinishLaunchingWithOptions中什么都不做,除了返回YES。我刚刚在这个ViewController中添加了一个UIImageView。是否可以使这个方向有效?

I've also checked the plist file, both orientations are present there. On my storyboard, at Simulated Metrics Orientation is set to Inferred. I do nothing in my applicationDidFinishLaunchingWithOptions, except return YES. I've just added a UIImageView inside of this ViewController. Is it possible to make this orientation work?

推荐答案

supportedInterfaceOrientations 返回一个 NSUInteger 。它返回视图控制器支持的所有接口方向,接口方向值的掩码。

supportedInterfaceOrientations returns an NSUInteger. It returns all of the interface orientations that the view controller supports, a mask of interface orientation values.

您需要返回 UIInterfaceOrientationMask中定义的值枚举,如下所示:

You need to return values defined in UIInterfaceOrientationMask Enum, like the following shows:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

这篇关于无法将界面方向旋转为纵向倒置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆