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/