Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个程序,里面有一堆按钮,我想做一个动作,所以你得到了被按下的按钮的坐标,但没有为每个人做一个动作。我想,你可以在一个动作中以某种方式从(id)发送者那里获取坐标,但我不知道如何。
此操作方法测试发送方是否派生自UIControl(因此它可以安全地将idto强制转换UIControl *)并显示控件的frame:
UIControl
id
UIControl *
frame
- (void)myAction:(id)sender { if ([sender isMemberOfClass:[UIControl class]]) { UIControl *control = (UIControl *)sender; NSLog(@"control frame=%@", NSStringFromCGRect(control.frame)); } }