您的位置:首页 > 移动开发 > IOS开发

ios屏幕旋转 项目中应用

2014-05-13 16:43 363 查看
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;

}

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

- (NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskLandscape;

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