ios 相机界面强制横屏

来源:互联网 发布:app慢动作拍摄软件 编辑:程序博客网 时间:2024/05/16 06:51

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

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

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    returnUIInterfaceOrientationLandscapeLeft;

}


- (NSUInteger)supportedInterfaceOrientations{

    returnUIInterfaceOrientationMaskLandscape;

}


- (BOOL)shouldAutorotate {

    returnYES;

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {

        returnYES;

    } else {

        returnNO;

    }

}

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

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

{

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

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

        returnUIInterfaceOrientationMaskAll;

    }

    return [applicationsupportedInterfaceOrientationsForWindow:window];

}


0 0
原创粉丝点击