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;
}
因为在做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;
}
相关文章推荐
- IOS Orientation, 想怎么转就怎么转~~~ 此博文主要针对IOS应用, 是屏幕旋转相关问题的一个总结. 主要内容有: IOS5,6,7不同版的适配. 强制旋转和自动旋转.
- iosUIImage图片反响旋转(内存消耗超大基本应用不到项目中,有大神能解决求告知)
- 修改iOS应用屏幕出现黑边
- iOS开发中屏幕旋转至一个方向后再手动设置屏幕旋转至该方向无效问题
- Android项目旋转屏幕数据丢失的原因及解决
- 一款ios版本的IM聊天应用项目源码
- ios项目应用图标icon和default图片命名规则
- ios应用屏幕兼容问题
- iOS中的手势识别的积累:UIGestureRecognizer(轻拍手势,长按手势,清扫手势,平移手势,捏合手势,旋转手势,屏幕边缘平移手势) ----仿射变换
- Facebook发布开源项目Tweaks,让iOS应用开发更加便捷
- #坑2# 强制旋转应用当前屏幕
- 【转载】iOS开发之屏幕旋转
- iOS屏幕强制旋转
- iOS 屏幕旋转问题
- IOS开发之——手动设置屏幕旋转
- iOS两个强制旋转屏幕的方法
- ios 屏幕旋转监测
- iOS 屏幕旋转问题总结
- iOS Orientation 屏幕旋转
- IOS UIDevice & IOS检测屏幕旋转实例