iOS 横竖屏的切换以及个别界面横屏

    xiaoxiao2021-03-26  35

    进入正文前先认识几个概念      portrait  竖屏(Home键在下边)      upside down  竖屏(Home键在上边)      landscape  横屏   |landscape left  横屏Home键在左边                                   |landscape right 横屏Home键在右边 1、先让窗口支持横竖屏      两种方法可以修改窗口对横竖屏的支持      一种,代码控制       在appDelegate中重写方法,比如 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {     if (self.isShouAutoRotate) {         return UIInterfaceOrientationMaskAll;     }     return UIInterfaceOrientationMaskPortrait; }       另一种就是,在【General】-->【Device Orientation】中设置好支持的方向       如图,,,,,,      两种方法的利弊,读者自己推敲。 2、下面认识三个方法 // 是否自动旋转 - (BOOL)shouldAutorotate {     return YES; } // 返回支持的方向 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskLandscapeRight; } // 切换横竖屏时,可以重写这个方法,来重新布局界面 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {} 3、个别界面横屏      第一种处理方式:   1中对应的设置支持横屏完成后,在相应的控制器直接实现2中的方法二      第二种处理方式:   1中对应的设置支持横屏完成后,在相应控制器的viewDidLoad方法中强制设置设备朝向,代码如下:     NSNumber *value = [NSNumber numberWithInt:4];

        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

    看完是不是很想吐槽,来吧,评论等着你

    转载请注明原文地址: https://ju.6miu.com/read-661030.html

    最新回复(0)