ios 屏幕旋转,横屏竖屏
来源:互联网 发布:二次元pv制作软件 编辑:程序博客网 时间:2024/06/05 07:05
最近做了一点关于屏幕旋转的东西,第一次做,搞的焦头烂额,所幸在同事的帮助下完成了,现在记录一下,便于以后查看。
1.首先需要在General里,Deployment info 里根据自己的需求设置Device Orientation。
Portrait代表竖屏Landscape代表横屏
2.如果是想要自动根据手机的方向横竖屏的话设置下面两个方法
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
3如果想手动控制横竖屏,就用下面的方法
添加按钮的方法
[UIDevice currentDevice] orientation]可以取到当前屏幕的方向
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait)
{
[self setfullScreen];
}
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)
{
[self setsmallScreen];
//横屏
- (void)setfullScreen
{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
}
//竖屏
- (void)setsmallScreen
{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
然后旋转后的frame需要根据自己需要设置
还有一种横屏方法为强制横屏,在view上添加一个window,然后把window强制旋转,但是这样做键盘还是竖屏,可以根据需要选择
下面直接上方法
- (void)setLandScapeViewWithOrientation:(UIDeviceOrientation)orientnation
{
if (UIDeviceOrientationIsLandscape(orientnation)) {
if (_landScapeWindow == nil) {
CGRect screenFrame = [UIScreen mainScreen].bounds;
_landScapeWindow = [[UIWindow alloc] initWithFrame:CGRectMake(screenFrame.size.width/2 - screenFrame.size.height/2, screenFrame.size.height/2 - screenFrame.size.width/2, screenFrame.size.height, screenFrame.size.width)];
_landScapeWindow.windowLevel = UIWindowLevelStatusBar + 1;
_landScapeWindow.center = CGPointMake(screenFrame.size.width/2, screenFrame.size.height/2);
CGFloat angle = M_PI_2;
if (orientnation == UIDeviceOrientationLandscapeRight) {
angle = M_PI_2 + M_PI;
}
_landScapeWindow.transform = CGAffineTransformIdentity;
_landScapeWindow.transform = CGAffineTransformMakeRotation(angle);
_landScapeWindow.hidden = NO;
} else if (UIDeviceOrientationIsPortrait(orientnation)) {
_landScapeWindow.hidden = YES;
}
}
}
- ios 屏幕旋转,横屏竖屏
- ios 屏幕旋转,横屏竖屏
- iOS手动旋转屏幕、自动旋转屏幕
- ios屏幕旋转注意事项
- iOS强制旋转屏幕
- ios 锁定 屏幕旋转
- ios旋转屏幕总结
- [IOS] 屏幕旋转控制
- iOS屏幕旋转
- 手动旋转iOS屏幕
- iOS屏幕旋转
- ios屏幕旋转
- iOS屏幕旋转
- IOS屏幕旋转
- iOS 屏幕旋转
- ios屏幕强制旋转
- ios 屏幕旋转
- ios屏幕旋转
- 总结一下C语言中的数组
- MediaInfo库获取视频信息
- 判断一个数是不是素数,若不是,则找出其中一对因子
- QML 语言基础
- Eclipse报错中用Spring mvc初始化ContextLoaderListener报错
- ios 屏幕旋转,横屏竖屏
- iOS中的沙盒机制(SandBox)以及获取路径方法
- SAP IDoc 简介
- 图像相似度计算之哈希值方法OpenCV实现
- Eclipse中10个最有用的快捷键组合
- centos6.4 安装mysql(the easiest way and best way)
- 用awk一些常用技巧sort uniq
- @GeneratedValue
- Cocos2d-x v3.2 例程中的 SpriteBlur