在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发展
相关资讯


