IOS 屏幕旋转

来源:互联网 发布:c语言函数返回布尔值 编辑:程序博客网 时间:2024/05/19 17:07

1.info.plist文件设置支持旋转的方向(此处只是示例,具体方向根据需求)


2.viewController中选择支持的方向

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;//只支持这一个方向(正常的方向)
}


3.如果是NavigationController push的子页,可以写一个自己的MyNavigationController 继承 UINavigationController实现以下方法

-(BOOL)shouldAutorotate {
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations {
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

0 0