IOS屏幕旋转控制

UIViewController里覆盖如下方法:

 

//是否支持旋转
-(BOOL)shouldAutorotate{
return YES;
}

//支持哪些方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}

//旋转时做的事
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(UIInterfaceOrientationLandscapeLeft == toInterfaceOrientation){
NSLog(@"%f",duration);
}
}

 

 利用通知中心来监控方向变动

写道
//利用通知中心来监控方向变动
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrg:) name:UIDeviceOrientationDidChangeNotification object:nil];
- (void)deviceOrg:(NSNotification *) notication{
    UIDevice *device = (UIDevice *)[notication object];
    NSLog(@"orientation:%d",device.orientation);
}

  

猜你喜欢

转载自squll369.iteye.com/blog/2256159