码迷,mamicode.com
首页 > 移动开发 > 详细

ios 相机界面强制横屏

时间:2015-03-17 15:50:22      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:orientation   ios8   ios7   相机   强制横屏   

IOS调用系统的相机默认是竖屏的,网上找了很多方法强制横屏都无效,以下代码经测试兼容ios78

自定义一个UIImagePickerController并且覆盖以下方法:

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationLandscapeLeft;

}


- (NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskLandscape;

}


- (BOOL)shouldAutorotate {

    return YES;

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {

        return YES;

    } else {

        return NO;

    }

}

要兼容ios8还需要在delegate中加入以下代码

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

{

    NSString* strSubClass = [NSString stringWithUTF8String:object_getClassName(window.rootViewController.presentedViewController)];

    if ([@"ImgTakeViewController" isEqualToString:strSubClass]) {

        return UIInterfaceOrientationMaskAll;

    }

    return [application supportedInterfaceOrientationsForWindow:window];

}


ios 相机界面强制横屏

标签:orientation   ios8   ios7   相机   强制横屏   

原文地址:http://blog.csdn.net/dlmlzz09/article/details/44342515

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!