ios屏幕旋转 项目中应用

1.强制旋转

因为在做ipad横版适配,里面有个上传头像功能,拍照时旋转设备,拍照屏幕是旋转了,但返回前个视图时屏幕也随之旋转了,只好用强制旋转在返回前视图时处理下

方法如下:

if([UIDevice currentDevice] respondsToSelector:@selector(setOrientation:))

{

[[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)

UIInterfaceOrientationLandscapeRight

];

}


2.屏幕只能横屏适配ios7及以下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return UIInterfaceOrientationMaskLandscapeLeft || UIInterfaceOrientationMaskLandscapeRight;

}


-(BOOL)shouldAutorotate

{

    return YES;

}


-(NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskLandscape;

}


3.旋转当前view

问题出现在启动画面地方,应用启动时需要横屏,此时状态栏之类都旋转过来了,唯一当前的view跟我过不去,不旋转,哈哈,只好搞个动画旋转了。通过当前方向的判断作旋转角度。这方法虽然弱智,效果还是不错的哦。

-(void)statuBarFaceOrientation

{

    [UIView beginAnimations:@"ViewAnimation" context:NULL];

    /* Make the animation 5 seconds long */

    [UIView setAnimationDuration:0.0f];

    [UIView setAnimationDelegate:self];

    /* Commit the animation */

    [UIView commitAnimations];

    if ([UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationLandscapeRight) {

        //顺时针旋转90

        self.view.transform = CGAffineTransformMakeRotation((90.0f * M_PI) / 180.0f);

    }

    else

    {

        //逆时针旋转90

        self.view.transform = CGAffineTransformMakeRotation((90.0f * M_PI) / -180.0f);

    }

    [UIView commitAnimations];

}


3.ios7  UIImagePickerController选取本地图片只支持竖屏不能横屏的问题

应用横屏时,使用UIImagePickerController选取本地图片时崩溃,报libc++abi.dylib: terminate_handler unexpectedly threw an exception

错误,还好网上也有很多人遇到同样的问题,添加下面代码就不会报错,而且可以横屏了哦:

在你的application‘delegate中,继承如下方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    return UIInterfaceOrientationMaskAll;

}

然后在你的需要是用UIImagePickerControllerviewController中继承如下方法

- (NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskLandscape;

}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值