gpt4 book ai didi

iphone - 在 iOS 设备上处理触摸事件

转载 作者:行者123 更新时间:2023-11-28 18:06:29 24 4
gpt4 key购买 nike

我正在探索在 iOS 设备上处理触摸事件的方式。我提到了这本书:iOS Open Application Development .为此,我重写了 mouseDown、mouseUp 方法,并简单地在警告框中显示坐标。但是,重写的方法永远不会被调用。以下是派生自 UIView 的 newView 类的代码:

-(void) _mouseDown: (GSEventRef) event{
CGPoint point =GSEventGetLocationInWindow(event);
UIAlertView* alert;
NSString* alertString =[NSString stringWithFormat: @"%f %f", point.x, point.y];
alert = [[UIALertView alloc] initWithTitle:@"Success" message:alertString delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}

-(BOOL) canHandleGestures{
return YES;
}

有没有我遗漏的部分?另外,有没有其他方法可以获取有关触摸事件的信息并进行处理?

最佳答案

更好的起点是: https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/multitouch_background/multitouch_background.html

这些是您可以在 UIView 子类中覆盖的方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

关于iphone - 在 iOS 设备上处理触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14436064/

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