web应用开发&研究 - 创建于 2014年8月17日

这是一位web前端开发工程师的个人站,内容主要是网站开发方面的技术文章,大部分来自学习或工作,部分来源于网络,希望对大家有所帮助。

致力于web应用开发&研究工作,专注web前端开发,关注互联网前沿技术与趋势。


Font Awesome | Respond.js | Bootstrap中文网

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]

posted @ 2017-03-01 10:16  Star1108  阅读(2083)  评论(0编辑  收藏  举报