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