【发布时间】:2023-04-08 18:24:01
【问题描述】:
UIView 在设置框架时调用框架的 getter 方法。
下面是测试代码:
@interface Test: UIView
@end
@implementation Test
-(void) setFrame:(CGRect) frame {
super.frame = frame;
NSLog(@"Frame set!!!");
}
-(CGRect) frame {
NSLog(@"Frame!!!");
return super.frame;
}
@end
Test* inst = [[Test alloc] init];
inst.frame = CGRectMake(0, 0, 123, 123);
我发现它会在调用setFrame:时调用frame。
我很想知道那里发生了什么?有人知道吗?
仅供参考,输出是:
Frame!!!
Frame set!!! // Due to the call of initWithFrame:
Frame!!!
Frame set!!! // Setter
【问题讨论】:
-
询问苹果。他们编写了代码。
标签: ios objective-c uiview frame