`
squll369
  • 浏览: 106925 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

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);
}

  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics