问题
I have updated my Xcode to 4.5 , I have implemented the orientation methods as below
-(BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
I am setting the frame sizes of buttons ,labels,images in willRotateToInterfaceOrientation method
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait )||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown ))
{
// set frame sizes for portait
}
else if(( [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft )||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight ))
{
// set frame sizes for landscape
}
}
but sometimes this method is not getting called when rotating the simulator and sometimes the simulator is not detecting orientation when navigating from another viewController . I have checked info.plist file - it is fine.
回答1:
Apple does not call the shouldAutorotatetoInterfaceOrientation call in IOS 6.0 unless you tell the main window which view controller to send it to.
I got rotation to work in my app by setting the window.rootViewController to the top level view controller of my app in
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
window.rootViewController = topLevelViewController;
...
}
The iPhone version of my app only supports the two portrait orientations, so my top iPhone view controller required a new method:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait |
UIInterfaceOrientationMaskPortraitUpsideDown;
}
here is a discussion on Buzz Touch.
回答2:
Apple has deprecated shouldautorate method from ios6 use these methods instead
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
// Returns interface orientation masks.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);
来源:https://stackoverflow.com/questions/12565693/xcode-4-5-ios-6-0-simulator-orientation-not-working