两个强制屏幕旋转的方法

来源:互联网 发布:会计软件下载 编辑:程序博客网 时间:2024/06/09 19:08
第一个:
 
?
1
2
3
4
5
6
7
8
// 状态栏动画持续时间 
CGFloat duration = [UIApplicationsharedApplication].statusBarOrientationAnimationDuration; 
[UIView animateWithDuration:durationanimations:^{ 
    //修改状态栏的方向及view的方向进而强制旋转屏幕 
    [[UIApplicationsharedApplication]setStatusBarOrientation:_bottomView.landscapeModel ?UIInterfaceOrientationLandscapeRight :UIInterfaceOrientationPortrait]; 
    self.navigationController.view.transform= _bottomView.landscapeModel ?CGAffineTransformMakeRotation(M_PI_2) :CGAffineTransformIdentity; 
    self.navigationController.view.bounds= CGRectMake(self.navigationController.view.bounds.origin.x,self.navigationController.view.bounds.origin.y,self.view.frame.size.height,self.view.frame.size.width); 
}];

 

 
 
第二个:
非arc:
 
?
1
2
3
4
if ([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]){ 
  [[UIDevicecurrentDevice]performSelector:@selector(setOrientation:) 
  withObject:(id)UIInterfaceOrientationLandscapeRight]; 
  

 

 
arc下:
?
1
2
3
4
5
6
7
8
9
if ([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]){ 
            SELselector = NSSelectorFromString(@"setOrientation:"); 
            NSInvocation*invocation = [NSInvocation invocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]]; 
            [invocationsetSelector:selector]; 
            [invocationsetTarget:[UIDevice currentDevice]]; 
            intval =UIInterfaceOrientationLandscapeRight; 
            [invocationsetArgument:&val atIndex:2]; 
            [invocationinvoke]; 
        

 

0 0