iOS橫屏設置的幾種方式


1.界面旋轉,MainScreen的寬高不變,鍵盤位置不變

CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:duration];

self.view.transform =CGAffineTransformMakeRotation(M_PI/2);

[UIView commitAnimations];

 2.界面旋轉,MainScreen的寬高改變,鍵盤位置不變

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 = UIInterfaceOrientationLandscapeRight;

        [invocation setArgument:&val atIndex:2];

        [invocation invoke];
}

3.界面旋轉,MainScreen的寬高改變,鍵盤位置改變

a.General—>中勾選Lnadscape Left/Lnadscape Right,默認是勾選上了的

b.控制器中實現以下兩個方法:

// 支持設備自動旋轉
- (BOOL)shouldAutorotate
{
    return YES;
}

/**
 *  設置特殊的界面支持的方向,這里特殊界面只支持Home在右側的情況
 */
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}

 PS:如何判斷當前是否橫屏,一下3個方法都可以

    self.interfaceOrientation(iOS 2.0~8.0)

      [UIApplication sharedApplication] statusBarOrientation]

      [[UIDevice currentDevice] orientation]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM