iOS 界面自动旋转与自适应布局详解
1. 指定旋转支持
在开发 iOS 应用时,我们需要处理界面的自动旋转问题。在代码中,我们可以通过 shouldAutorotateToInterfaceOrientation: 方法来指定应用支持的界面方向。以下是该方法的示例代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
iOS 设备有四种常见的界面方向:
- UIInterfaceOrientationPortrait
- UIInterfaceOrientationPortraitUpsideDown
- UIInterfaceOrientationLandscapeLeft
- UIInterfaceOrientationLandscapeRight
对于 iPhone 项目,模板默认支持除上下颠倒以外的所有方向;而对于 iPad 项目,模板生成的 shouldAutorotateToInterf
超级会员免费看
订阅专栏 解锁全文
54

被折叠的 条评论
为什么被折叠?



