ios - 我们可以修改 iOS 中的 UIViewController 属性吗?

标签 ios cocoa-touch uiinterfaceorientation

iOS 有一个预先声明的属性,如下所示:

@property(nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;

我可以为我的项目将它修改为 @property(nonatomic) UIInterfaceOrientation interfaceOrientation;,然后在我的类的不同 Controller 方法中为“interfaceOrientation”变量分配不同的值吗?

如果我修改现有属性,是否会产生问题?

此外,在谷歌搜索时,我在某处读到如果 @property(nonatomic) 没有用“readonly”关键字声明,那么默认情况下它是可读写的。此规则是否仅适用于开发人员定义的属性而不适用于预定义的属性?

最佳答案

不,如果它是只读的,那是有原因的。要提供不同的行为,您应该子类化 UIViewController 并覆盖指定的方法 [1] [2] :

- (NSUInteger)supportedInterfaceOrientations
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

关于ios - 我们可以修改 iOS 中的 UIViewController 属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502070/

相关文章:

ios - ARC 语义问题 : No visible @interface for 'UIStoryboard' declares selector

ios - 如何在没有过滤器的情况下从设备中检索所有 CNContactStore

iPhone:获取相机预览

iphone - 以编程方式创建属性 - 核心数据

ios - iPad ios6 中的方向问题

iOS 开发 - 将城市与 NSTimezone 离线关联

iphone - 滚动时感觉滞后,同时从后台线程中的 Assets 加载全屏图像

iPhone:当用户触摸背景时关闭键盘

ios - 设备界面方向

objective-c - 无法检测负载方向 - iPad