广州达内培训

网站导航 联系我们

达内首页 > 职业前景 > 达内IOS培训分享:iOS6的旋屏控制技巧
达内IOS培训分享:iOS6的旋屏控制技巧
作者:广州达内科技 更新时间:2013-03-01 10:27 来源:Android开发培训

  在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInte***ceOrientation: 来单独控制某个UIViewController的旋屏方向支持,比如:
  [cpp] view plaincopyprint?
  - (BOOL)shouldAutorotateToInte***ceOrientationUIInte***ceOrientation)inte***ceOrientation
  {
  return (inte***ceOrientation == UIInte***ceOrientationPortrait);
  }
  但是在iOS6中,这个方法被废弃了,使用无效。
  shouldAutorotateToInte***ceOrientation:
  Returns a Boolean value indicating whether the view controller supports the specified orientation. (Deprecated in iOS 6.0. Override the supportedInte***ceOrientations andpreferredInte***ceOrientationForPresentation methods instead.)
  实践后会发现,通过supportedInte***ceOrientations的单独控制是无法锁定屏幕的。
  [cpp] view plaincopyprint?
  -(NSUInteger)supportedInte***ceOrientations
  {
  return UIInte***ceOrientationMaskPortrait;
  }
  多次实验后总结出控制屏幕旋转支持方向的方法如下:
  子类化UINavigationController,增加方法
  [cpp] view plaincopyprint?
  - (BOOL)shouldAutorotate
  {
  return self.topViewController.shouldAutorotate;
  }
  - (NSUInteger)supportedInte***ceOrientations
  {
  return self.topViewController.supportedInte***ceOrientations;
  }
  并且设定其为程序入口,或指定为 self.window.rootViewController
  随后添加自己的view controller,如果想禁止某个view controller的旋屏:(支持全部版本的控制)
  [cpp] view plaincopyprint?
  - (BOOL)shouldAutorotateToInte***ceOrientationUIInte***ceOrientation)inte***ceOrientation
  {
  return (inte***ceOrientation == UIInte***ceOrientationPortrait);
  }
  -(BOOL)shouldAutorotate
  {
  return NO;
  }
  -(NSUInteger)supportedInte***ceOrientations
  {
  return UIInte***ceOrientationMaskPortrait;
  }
  如果想又开启某个view controller的全部方向旋屏支持:
  [cpp] view plaincopyprint?
  - (BOOL)shouldAutorotateToInte***ceOrientationUIInte***ceOrientation)inte***ceOrientation
  {
  return (inte***ceOrientation != UIInte***ceOrientationPortraitUpsideDown);
  }
  -(NSUInteger)supportedInte***ceOrientations
  {
  return UIInte***ceOrientationMaskAllButUpsideDown;
  }
  -(BOOL)shouldAutorotate
  {
  return YES;
  }
  从而实现了对每个view controller的单独控制。
  顺便提一下,如果整个应用所有view controller都不支持旋屏,那么干脆:
  [cpp] view plaincopyprint?
  - (NSUInteger)applicationUIApplication *)application supportedInte***ceOrientationsForWindowUIWindow *)window
  {
  return UIInte***ceOrientationMaskPortrait;
  }
     达内IOS培训怎么样?IOS就业怎么样?选择达内IOS培训开启企业定制就业直通车,达内科技满足你高薪就业梦想!
      如果你对ios技术深感兴趣,如果你向往高薪职业,那么选择达内培训吧!ios培训背后隐藏着巨大的就业机会,而达内联合多个知名企业为学员谋求优质实习就业机会,达内ios培训的目的只有一个:保证学员的高质量就业!


上一篇:Android写入配置信息
下一篇:ADI:中国TD-SCDMA系统如何实现向TD-LTE发展

相关资讯

  • [2013-03-02 11:13:15] ADI:中国TD-SCDMA系统如何实现向TD-LTE发展
  • [2013-03-01 10:27:49] 达内IOS培训分享:iOS6的旋屏控制技巧
  • [2013-02-28 15:10:07] Android写入配置信息
  • [2013-02-27 16:22:21] 说说Android线程优先级设置方法
  • [2013-02-26 14:36:20] android培训之Android应用程序之间数据共享
  • [2013-02-25 10:11:30] 3G流媒体业务的QoS及解决之道
  • 【2013年1月18日】
    Java 软件工程师就业班
    >>热招中!


    【2013年1月12日】
    3G-Android 工程师就业班
    >>热招中!


    【2013年1月15日】
    3G-Android 工程师周末班
    >>热招中!

    【2013年1月15日】
    软件测试 工程师就业班
    >>热招中!