如何实现ios屏幕的横竖屏自适应

发布网友

我来回答

2个回答

热心网友

 在xcode的工程中,目前已经能够选择APP是否使用横屏还是竖屏了,但其实APP还是可以进行横竖屏切换。有几个办法

  1、代码法:

  C++代码

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
  //看下面的,自己可以调整,以达到你想要的效果,比如只能横屏显示,只能竖屏显示,或者直接返回YES,表示可以支持任何方向的旋转.
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }

  当然这段return中其实有很多判断:

  C++代码

  return (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight);
  
  //这里是支持哪个方向的转动
  
  return (toInterfaceOrientation == UIInterfaceOrientationPortrait)
  || (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft)
  || (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight)
  || (toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);

  2、其实还可以在代码之外操作:

  设置应用程序的横竖屏显示很简单,默认新建的工程,是支持左横屏,右横屏,竖屏三种方式的,若不希望横屏显示,只需要在工程的配置文件中删除掉横屏的两个item即可。

  记得在:Supported interface orientations 有三个项的,items0,如果你要固定横、竖屏,记得将items0展开看一下,如果不是自己需要,就删除吧。我在设置横屏的时候,就不需要这个items0。于是将它删除了

热心网友

推荐图吧地图,地图详细,而且定位准速度也快~

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com