iphone - 我的应用程序没有改变方向

标签 iphone ios orientation

我正在使用 XCode 4.6 和 iOS 6.1。但我的应用程序不会改变方向。我已将我的应用程序设置为支持 pList 中的方向并添加了方向更改方法。但是应用程序仍然没有改变方向。

enter image description here

enter image description here

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

我正在使用 TabBarController,我正在使用此代码添加它。

self.window.rootViewController = self.tabController;

在 iOS 6 模拟器中一切正常,但对于 iOS 5 它不起作用。

最佳答案

检查方向是否有效的代码?

代码::

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    ......
}

检查方法::

-(void)orientationChanged {

   NSLog(@"Orientation Changed..!!");
}

方向改变方法代码

在 PCH 文件中,

#define IOS_OLDER_THAN_6        ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )

在.m文件中,

//For Less than IOS 6

#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
   return toInterfaceOrientation;
}
#endif

// For Newer than IOS 6.
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate
{
   return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
   return (UIInterfaceOrientationMaskAll);
}
#endif

希望对您有所帮助。

谢谢。

关于iphone - 我的应用程序没有改变方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15431668/

相关文章:

iOS - 为什么表格 View 不显示?

ios - xcode 中的项目构建失败

ios - 从 map 中删除注释并替换为更新的注释 (qTree)

iphone - 固定 View Controller 的方向

android - 在 Android PhoneGap 中更改方向时 SplashScreen 未更改

Android 传感器偏航、俯仰和滚转

iphone - UIImagePicker 的内存问题

iphone - 如何在 iPhone SDK 中使用自定义字体?

ios - 减小 UIImage 大小不起作用

ios - 在 iPhone 上运行时出错,在模拟器上运行正常