ios 屏幕旋转,横屏竖屏
来源:互联网 发布:手机淘宝取消不了退款 编辑:程序博客网 时间:2024/05/22 10:45
最近做了一点关于屏幕旋转的东西,第一次做,搞的焦头烂额,所幸在同事的帮助下完成了,现在记录一下,便于以后查看。
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屏幕旋转
- wget命令
- Android静态安全检测 -> Activity组件暴露
- android xmlns:tools用法
- SurfaceView实现圆角矩形预览
- 8 个 jQuery 的 PDF 浏览插件
- ios 屏幕旋转,横屏竖屏
- Android自定义view详解
- ROS基础学习笔记(一)
- GCD 2种并发队列,2种串行对象的创建
- keepalived + redis配置
- opencv 骨架提取/图像细化
- java学习总结(16.07.12)java的枚举类
- 自定义圆形进度条 自定义倒计时进度条
- 关于spring security权限控制