iOS 怎样切换横竖屏

来源:互联网 发布:全球数据公司排名 编辑:程序博客网 时间:2024/06/10 01:25


上一篇文章是写我实现横竖屏之后遇到的问题,这里说一下是怎么实现横竖屏的


首先,因为我做的是其他页面禁止横屏,只要一个页面横屏,那么第一步,需要在AppDelegate中设置只能竖屏 然后在指定界面开启横屏.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.spOrientation =UIInterfaceOrientationMaskPortrait;

    return YES;

    

}

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    

    returnself.spOrientation;

}


下面是指定页面开启横屏

-(void)viewWillAppear:(BOOL)animated{

   AppDelegate * delegate = [UIApplicationsharedApplication].delegate;

    delegate.spOrientationUIInterfaceOrientationMaskAll;

}

-(void)viewWillDisappear:(BOOL)animated{

   AppDelegate * delegate = [UIApplicationsharedApplication].delegate;

    delegate.spOrientationUIInterfaceOrientationMaskPortrait;

}


因为前一个页面要求禁止横屏 则需要在上一个页面写 


- (void)viewWillAppear:(BOOL)animated {


    [superviewWillAppear:animated];

    

    [[UIDevicecurrentDevice] setValue: [NSNumbernumberWithInteger: UIInterfaceOrientationPortrait]forKey:@"orientation"];

}


这样就做到横竖屏切换啦

1 0
原创粉丝点击