手机
当前位置:查字典教程网 >编程开发 >IOS开发 >ios开发过程中屏幕方向判断的问题
ios开发过程中屏幕方向判断的问题
摘要:Landscape竖屏Portrait横屏最有效的方法是:在willRotateToInterfaceOrientation:duratio...

Landscape 竖屏Portrait 横屏最有效的方法是:在willRotateToInterfaceOrientation:duration:方法中将方向存储起来:DrviceOrientation = toInterfaceOrientation;然后在别的方法中使用相应的屏幕的方向方法一:直接获取设备的方法:self.interfaceOrientation(此方法已经过期)方法二:通过下面的方法:UIDeviceOrientation duration = [[UIDevice currentDevice]orientation];方法

1、2当在模拟器中运行时,刚开始获得的设备方向为UnKnow方法三跟据屏幕的宽度计算相应的屏幕的方向[[UIScreenmainScreen] applicationFrame].size.height[[UIScreenmainScreen] applicationFrame].size.width可以用来获取当前屏幕的尺寸,高和宽。由于系统的状态条占高20且总是在屏幕上方,它使得上面两个值在横竖屏的时候有变化,因此可用来判断当前是横屏还是竖屏。简单的说竖屏时,height为1004,width为768。横屏时,height为1024,width为748。

当然 ,前提是你没有把系统的状态栏去掉.它可以用在任何方法内作为判断条件.应用示例如下:if (loadingview ==nil){ loadingview = [[UIViewalloc] initWithFrame:CGRectMake(284, 402, 200, 200)]; if ([[UIScreenmainScreen] applicationFrame].size.height==1024) { loadingview.frame=CGRectMake(412, 264, 200, 200);//此时为横屏 } [loadingviewsetBackgroundColor:[UIColorclearColor]];}//创建loadingview的时候根据当前横竖屏设定位置。方法四 在论坛里已经有人发过了(我在这里仅做了简单的搬运工作)//下面则是直接以屏幕方向判断- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {switch (interfaceOrientation) { caseUIInterfaceOrientationPortrait: //home健在下 break; caseUIInterfaceOrientationPortraitUpsideDown: //home健在上 break; caseUIInterfaceOrientationLandscapeLeft: //home健在左 break; caseUIInterfaceOrientationLandscapeRight: //home健在右 break; default: break; }方法五再屏幕旋转的时候记录下来屏幕的方向 着样做的画需要再窗后启动的时候让屏幕进行一次旋转,否则的画当程序启动的时候 屏幕的方向会有问题#pragma mark 屏幕旋转完成-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ NSLog(@"屏幕旋转完成 dockView的高度%f",self.dockView.height); //self.dockView.width = self.dockWidth;}#pragma mark 屏幕将旋转-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ [UIView animateWithDuration:0.25 animations:^{ self.dockView.width = self.dockWidth; }]; // 判断横竖屏 if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { NSLog(@"屏幕将旋转 为 竖屏"); self.dockView.width = self.dockWidth; }else{ NSLog(@"屏幕将旋转 为 横屏"); self.dockWidth = 100; }}

【ios开发过程中屏幕方向判断的问题】相关文章:

iOS开发实现下载器的基本功能(1)

iOS开发:队列和信号量该如何同步

iOS开发中常见的项目文件与MVC结构优化思路解析

iOS应用中使用Toolbar工具栏方式切换视图的方法详解

iOS开发中Date Picker和UITool Bar控件的使用简介

iOS App开发中通过UIDevice类获取设备信息的方法

iOS App开发中使cell高度自适应的黑魔法详解

iOS开发中ViewController的页面跳转和弹出模态

iOS开发之运动事件和远程控制

开发iOS应用程序前需要解决的十大问题

精品推荐
分类导航