您的位置:首页 > 其它

设置视图控制器的旋转方向

2015-10-11 15:56 309 查看
设置视图控制器的旋转方向

//当控制器旋转的时候执行的方法
/*
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,
UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
};
*/
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

CGFloat width = [UIScreen mainScreen].bounds.size.width;

CGFloat height = [UIScreen mainScreen].bounds.size.height;
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
{
UIView *view = [self.view viewWithTag:100];
view.frame = CGRectMake((width - 100) / 2, (height - 100) / 2, 100, 100);
break;

}
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
{

UIView *view = [self.view viewWithTag:100];
view.frame = CGRectMake((height - 100) / 2, (width - 100) / 2, 100, 100);
break;

}
default:
break;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: