简体   繁体   中英

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

I use codes below to change orientation of a view controller:

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

It can force orientation to landscape, but I can not make it work with disabling auto rotate:

-(BOOL)shouldAutorotate {
    return NO;
}

Is this possible to change orientation with a button event but disable auto rotate?

Declare a boolean variable check and then on the basis of the value you can enable or disable 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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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