巴顿TouchesMoved? [英] TouchesMoved with Button?

查看:117
本文介绍了巴顿TouchesMoved?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用的按钮,而不是的UIImageView S中的 touchesMoved 功能?

Is it possible to use the touchesMoved function with buttons instead of UIImageViews?

推荐答案

在您的.h文件中

IBOutlet UIButton *aButton;

在您的.m文件

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event touchesForView:self.view] anyObject];

    CGPoint location = [touch locationInView:touch.view];

    if(CGRectContainsPoint(p1.frame, location)) 
    {
        if (!p1.isHighlighted){
            [self pP01];
            [p1 setHighlighted:YES];
    }
}else {
        [p1 setHighlighted:NO];
    }
    //
    if(CGRectContainsPoint(p2.frame, location)) 
    {
        if (!p2.isHighlighted){
            [self pP02];
            [p2 setHighlighted:YES];
        }
    }else {
        [p2 setHighlighted:NO];
    }
    if(CGRectContainsPoint(p3.frame, location))
    {
        if (!p3.isHighlighted){
            [self pP03];
            [p3 setHighlighted:YES];
        }
    }else {
        [p3 setHighlighted:NO];
    }
}

最后,在Interface Builder中,你的按钮连接到'A按钮和关闭作为您的按钮用户启用互动。
因为它允许touchesMoved处理它,这是很重要的。

And finally, in Interface Builder, connect your button to 'aButton' and turn off "User Interaction Enabled" for your button. This is important because it allow touchesMoved to handle it.

我已经调整上述code,检查按钮高亮显示状态。这是从多次发射按钮,当你拖动手指在禁区内停下来。

I have adjusted the code above to check the buttons highlighted state. This is to stop it from firing the button multiple times when you drag your finger inside the area.

要得到你的钢琴键,当你点击它们,来变通 - (空)的touchesBegan

To get your "piano keys" to work when you tap them, use -(void)touchesBegan

要设置按钮高亮状态返回到 = NO; ,使用 - (无效)touchesEnded

To set your button highlight states back to = NO;, use -(void)touchesEnded

我不得不找出你是后同样的事情。我无法弄清楚触摸拖拽输入

I have had to find out the exact same thing you are after. I couldn't figure out Touch Drag Enter

因此​​,为了避免关于这个问题的多篇文章,请看看我的问题和答案。

So to avoid multiple posts on the subject, please check out my question and answers.

<一个href=\"http://stackoverflow.com/questions/2286305/how-do-you-get-multiple-touch-buttons-to-work-with-touchesbegan-moved\">question 1

<一个href=\"http://stackoverflow.com/questions/2234822/how-to-call-a-method-only-once-during-voidtouchesmoved\">question 2

这篇关于巴顿TouchesMoved?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆