首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >同时在两个按钮中进行一次触摸

同时在两个按钮中进行一次触摸
EN

Stack Overflow用户
提问于 2011-09-17 04:11:25
回答 2查看 254关注 0票数 0

我的应用程序有两个按钮,近旁。

我试着用一根手指同时触摸这两个按钮。

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

EN

Stack Overflow用户

回答已采纳

发布于 2011-09-17 05:28:54

你可以(但确实不应该)像Abizern说的那样用一根手指触摸两个按钮,但你也可以调用两个方法来实现一个按钮的触摸。例如:

代码语言:javascript
运行
复制
-(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和事件机制来解决很多问题:

代码语言:javascript
运行
复制
- (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
        }
    }

}

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7449896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档