Click on the button / / landscape - (void) leftAction {[self interfaceOrientation: UIInterfaceOrientationLandscapeLeft]; Click on the button} / / vertical screen - (void) rightAction {[self interfaceOrientation: UIInterfaceOrientationPortrait]; } -(BOOL)shouldAutorotate{ return YES; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft); } - (void)interfaceOrientation:(UIInterfaceOrientation)orientation { if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; int val = orientation; The invocation starts from 2 because 0 and 1 are already used by selector and target [Invocation setArgument:&val atIndex:2]; [invocation invoke]; }}Copy the code

Realize the effect drawing