gpt4 book ai didi

iphone - 同时按两个按钮

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

我的应用有 2 个按钮,靠近。

我想同时触摸这两个按钮,只用一根手指。

有没有办法检查触摸是否同时在这两个按钮上?

最佳答案

你可以(但真的不应该)像 Abizern 说的那样用一根手指触摸 2 个按钮,但是你也可以为一个按钮触摸调用 2 个方法。例如:

-(void)viewDidLoad {
self.myButton = /*initialize the button*/;
[self.myButton addTarget:self action:@selector(callTwoMethods) forControlEvents:UIControlEventTouchUpInside];
}

-(void)callTwoMethods {
[self methodOne];
[self methodTwo];
}

但是,对于您要尝试执行的操作而言,这并不总是正确的行为,因此从 iOS 3 开始,我们可以使用 UITouch 和事件机制进行一些调整来解决很多问题:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([touches count] == 2) {
//we are aware of two touches, so get them both
UITouch *firstTouch = [[allTouches allObjects] objectAtIndex:0];
UITouch *secondTouch = [[allTouches allObjects] objectAtIndex:1];

CGPoint firstPoint = [firstTouch locationInView:self.view];
CGPoint secondPoint = [secondTouch locationInView:self.view];

if ([self.firstButton pointInside:firstPoint withEvent:event] && [self.secondButton secondPoint withEvent:event] || /*the opposite test for firstButton getting the first and secondButton getting the second touch*/) {
//Do stuff
}
}

关于iphone - 同时按两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7449896/

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