按下按钮时有一个UIEvent,在NSLog中,它返回为:
<UITouchesEvent: 0x4b13210> timestamp: 3764.51 touches: {(
<UITouch: 0x4b1edf0> phase: Began tap count: 1 window: <UIWindow: 0x4b342b0; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x4b34400>> view: <UIView: 0x4b356c0; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x4b33990>> location in window: {121, 377} previous location in window: {121, 377} location in view: {121, 357} previous location in view: {121, 357}
)}
我如何获得某些信息,例如图层框架。
答案 0 :(得分:4)
按下按钮时,与事件关联的所有触摸都将作为一组UITouch对象传递给函数“fntButtonPress”。 你需要做的是找到你的目标。 在此示例中,根据您的请求,向您展示如何从触摸设置中获取图层。
[YourButton addTarget:self action:@selector(fntButtonPress:event:) forControlEvents:UIControlEventTouchUpInside];
- (void) fntButtonPress:(id)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CALayer *touchedLayer = [touch view].layer;
}
答案 1 :(得分:2)