gpt4 book ai didi

iphone - 如何从触摸事件中获取信息?

转载 作者:行者123 更新时间:2023-12-03 20:28:39 25 4
gpt4 key购买 nike

我在按下按钮时有一个 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}
)}

我如何获取其中一些信息,例如图层框架。

最佳答案

按下按钮时,与事件关联的所有触摸都将作为一组 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;
}

关于iphone - 如何从触摸事件中获取信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5925461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com