• 爱情文章
  • 亲情文章
  • 友情文章
  • 生活随笔
  • 校园文章
  • 经典文章
  • 人生哲理
  • 励志文章
  • 搞笑文章
  • 心情日记
  • 英语文章
  • 范文大全
  • 作文大全
  • 新闻阅读
  • 当前位置: 山茶花美文网 > 搞笑文章 > 正文

    ios 判断屏幕方向 [ios开发过程中屏幕方向判断的问题]

    时间:2020-05-26来源:山茶花美文网 本文已影响 山茶花美文网手机站

    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开发过程中屏幕方向判断的问题] 相关文章:
    • 爱情文章
    • 亲情文章
    • 友情文章
    • 随笔
    • 哲理
    • 励志
    • 范文大全