本篇文章主要介绍了"iOS实现部分页面支持横屏显示,部分页面只能竖屏显示",主要涉及到方面的内容,对于IOS开发感兴趣的同学可以参考一下:
因为项目有这样一个需求,查看图片页面需要支持横竖屏切换,而其他页面只支持竖屏显示。首先在项目设置中勾选需要支持的方向,然后在不需要支持旋转的页面加入如下代码:/...
因为项目有这样一个需求,查看图片页面需要支持横竖屏切换,而其他页面只支持竖屏显示。首先在项目设置中勾选需要支持的方向,然后在不需要支持旋转的页面加入如下代码:
// iOS6及以上
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
// ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskPortrait);
}
另外附上一段强制横竖屏的代码:
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:[[NSNumber alloc] initWithInt:UIInterfaceOrientationPortrait]];
}
以上就介绍了iOS实现部分页面支持横屏显示,部分页面只能竖屏显示,包括了方面的内容,希望对IOS开发有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_98703.html