屏幕旋转--强转(可用)

来源:互联网 发布:vb中range对象 编辑:程序博客网 时间:2024/05/22 13:00


 if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])

            {
                
                NSNumber *num = [[NSNumber alloc] initWithInt:(m_bScreen?UIInterfaceOrientationLandscapeRight:UIInterfaceOrientationPortrait)];
                
                
                
                [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)num];
                
                [UIViewController attemptRotationToDeviceOrientation];//这行代码是关键
                
            }
            
            SEL selector=NSSelectorFromString(@"setOrientation:");
            
            NSInvocation *invocation =[NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
            
            [invocation setSelector:selector];
            
            [invocation setTarget:[UIDevice currentDevice]];
            
            int val =m_bScreen?UIInterfaceOrientationLandscapeRight:UIInterfaceOrientationPortrait;
            
            [invocation setArgument:&val atIndex:2];
            
            [invocation invoke];

0 0