给定(任意):
CGRect frame = CGRectMake(0.0f, 0.0f, 100.0f, 30.0f);
Run Code Online (Sandbox Code Playgroud)
以下两个代码片段之间的区别是什么?
1.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
Run Code Online (Sandbox Code Playgroud)
2.
UIButton *button = [[[UIButton alloc] initWithFrame:frame] autorelease];
Run Code Online (Sandbox Code Playgroud) 我试着弄清楚事情是如何运作的.所以我想当我用类别覆盖某些方法时,我会得到有趣的NSLogs.
@implementation UIView(Learning)
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
NSLog(@"-hitTest:withEvent: event=%@", event);
return [self hitTest:point withEvent:event];
}
@end
Run Code Online (Sandbox Code Playgroud)
超级和自我在这里不起作用.有没有办法调用-hitTest的原始实现:withEvent:?我想要的是NSLog每次-hitTest:withEvent:在UIView上调用.
这仅用于个人学习目的.我希望看到活动的实施.
objective-c swizzling ios objective-c-category method-swizzling