supportedInterfaceOrientations设备支持方向
preferredInterfaceOrientationForPresentation 方法提供的择优的方向取向
ios5
重写 shouldAutorotateToInterfaceOrientation: 方法和指示您的视图支持哪个方向
监听屏幕方向变化
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
//处理旋转之后的操作
- (void)orientationChanged:(NSNotification *)notification
- (NSUInteger)supportedInterfaceOrientations |
{ |
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft; |
} |
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation |
{ |
return UIInterfaceOrientationLandscapeLeft; |
} |
ios5
重写 shouldAutorotateToInterfaceOrientation: 方法和指示您的视图支持哪个方向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation |
{ |
if ((orientation == UIInterfaceOrientationPortrait) || |
(orientation == UIInterfaceOrientationLandscapeLeft)) |
return YES; |
return NO; |
} |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
//处理旋转之后的操作
- (void)orientationChanged:(NSNotification *)notification