iOS 6 supportedInterfaceOrientations问题 [英] iOS 6 supportedInterfaceOrientations issue
问题描述
在我的视图控制器中,我实现两种控制接口方向的方法:
In my view controller, I implement two methods for controlling interface orientation:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return YES;
}
在 supportedInterfaceOrientations
方法,我返回 UIInterfaceOrientationMaskPortrait
但是当时我意识到 shouldAutorotate
方法未被调用。
In the supportedInterfaceOrientations
method, I return UIInterfaceOrientationMaskPortrait
but at that time I realized that the shouldAutorotate
method is not being called.
但我改变为 supportedInterfaceOrientations
方法中的 return UIInterfaceOrientationPortrait
。 shouldAutorotate
方法正在被调用,但有一个错误提到以下内容:
But I change to return UIInterfaceOrientationPortrait
in the supportedInterfaceOrientations
method. The shouldAutorotate
method is being called, but there is an error that mentions in following:
UIApplicationInvalidInterfaceOrientation
,原因:'支持的方向与应用程序没有共同的方向,shouldAutorotate正在返回YES'
UIApplicationInvalidInterfaceOrientation
, reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
顺便说一下,我选择了支持的界面方向的所有方向。
By the way, I select all orientations in the supported interface orientations.
EDITED
我使用viewController和嵌入与navigationController。
这里是AppDelegate.h
i use viewController and embed with navigationController. here is AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate,UINavigationControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (readonly, strong, nonatomic) UINavigationController *navController;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
在AppDelegate.m
in didFinishLaunchingWithOptions method under AppDelegate.m
navController = (UINavigationController *)self.window.rootViewController;
IPad_HomeViewController *rootVC=(IPad_HomeViewController *)navController.topViewController;
rootVC.managedObjectContext = self.managedObjectContext;
return YES;
在我的IPad_HomeViewController中,
in my IPad_HomeViewController,
@interface IPad_HomeViewController : UIViewController <UINavigationControllerDelegate>
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@end
推荐答案
- (BOOL) shouldAutorotate {
return YES;
}
// for landscape
- (NSInteger) supportedInterfaceOrientations {
return (1 << UIInterfaceOrientationLandscapeLeft) |
(1 << UIInterfaceOrientationLandscapeRight);
}
如上所述,检查特定方向的掩码值:UIInterfaceOrientationMask值。 UIInterfaceOrientationMask
As noted above, check out the mask values for specific orientations : UIInterfaceOrientationMask values.UIInterfaceOrientationMask
这篇关于iOS 6 supportedInterfaceOrientations问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!