iOS屏幕旋转

来源:互联网 发布:java程序员要学什么 编辑:程序博客网 时间:2024/04/28 15:41

4.具体实现方式

1创建一个OrientationNavigationController类继承UINavigationConroller,重写两个方法

#pragma mark-支持自动转屏

-(NSUInteger)supportedInterfaceOrientations

{

    //返回顶层视图支持的旋转方向

    return self.topViewController.supportedInterfaceOrientations;

}

- (BOOL)shouldAutorotate

{

    //返回顶层视图的设置

    return self.topViewController.shouldAutorotate;

}

 

(2)AppDelegate中,用此类创建一个导航,并设置成window的根视图

_OrientationNav= [[OrientationNavigationController alloc] initWithRootViewController:self.OrientationView1];

 

self.window.rootViewController=self.OrientationNav;

3)在各自的viewConroller中再重写四个方法,其中最后一个是为了兼容IOS6以下的版本了保留的

#pragma mark-旋屏的方法设置

-(NSUInteger)supportedInterfaceOrientations

{

    [self setMyLayout];

    return UIInterfaceOrientationMaskAllButUpsideDown;

}

- (BOOL)shouldAutorotate

{

    return YES;

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(3_0)

{

    [self setMyLayout];//检测到旋转时就会被调用

}

//为了兼容IOS6以前的版本而保留的方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

    //return (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);

    return YES;//即在IOS6.0以下版本,支持所用方向的旋屏

}

 

(4)然后写一个排版的函数,注意需要在viewwillappear、 supportedInterfaceOrientations 、willAnimateRotationToInterfaceOrientation三处都要重排一下

5)由view1跳转到view2中用 presentModalViewControllerf方式

0 0
原创粉丝点击