繁体   English   中英

是否可以通过按钮事件更改方向但禁用自动旋转?

[英]Is it possible to change orientation with a button event but disable auto rotate?

我使用下面的代码来更改视图控制器的方向:

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];

它可以迫使方向变为横向,但是我不能通过禁用自动旋转来使其工作:

-(BOOL)shouldAutorotate {
    return NO;
}

是否可以通过按钮事件更改方向但禁用自动旋转?

声明布尔变量检查,然后根据该值可以启用或禁用Orientaion。

   - (IBAction)someButton:(id)sender {
       [self changeOrientation];
            }

    -(void)changeOrientation
    {
        check = true;
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];

    }

    -(BOOL)shouldAutorotate {
        if (check) {
            return YES;
            check = false;

        }
        return NO;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM