开发者

How do i grab the info from a touches event?

开发者 https://www.devze.com 2023-03-04 20:10 出处:网络
I have a UIEvent on a button pre开发者_Python百科ss, and in NSLog this returns as: <UITouchesEvent: 0x4b13210> timestamp: 3764.51 touches: {(

I have a UIEvent on a button pre开发者_Python百科ss, and in NSLog this returns as:

<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}
)}

How can i get to some of this information, such as the layer frame.


when button pressed, all touches associated with an event will pass to function "fntButtonPress" as a set of UITouch objects. What you need to do, is to find you target from them. In this example, as you request, show you how to get layer from touches set.

[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;
}


The UIEvent object has a collection of UITouch's. The UITouch object gives you access to window and view properties which in turn provide access to the corresponding frame, layer, etc.

References: UIEvent, UITouch

0

精彩评论

暂无评论...
验证码 换一张
取 消