如何当用户在iPhone上对他们滑出自己的手指创造出被激活按钮 [英] How to create buttons which are activated when the user slides their finger over them on iPhone

查看:193
本文介绍了如何当用户在iPhone上对他们滑出自己的手指创造出被激活按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写有一样的界面,钢琴iPhone应用程序。用户是与一些大按钮,它们之间没有空格psented $ P $。目前我已经通过右键鼠标拖动按钮进入相应的视图控制器的接口文件创建在Interface Builder IBActions。这就产生了一个方法:

I'm writing an iPhone application which has a piano like interface. The user is presented with a number of large buttons with no spaces between them. At the moment I've created IBActions in Interface Builder by right mouse dragging the buttons into the appropriate view controller interface file. This creates a method:

-(IBAction) buttonTouchDown: (id) sender

在此函数的主体,我包括了code这是为了响应这一行动。

In the body of this function I've included the code which responds to this action.

当我轻点按钮,但是,但是当我拖我的手指在一个数字按钮只有第一个启动的这个工程。当我拖我的手指在按键我需要的第一个激活,而我的手指在它。然后,当我的手指离开按钮,进入第二个按钮,我需要第二次激活和第一停用。

This works when I tap the button but but when I drag my finger over a number of buttons only the first one activates. When I drag my finger over the buttons I need the first one to activate while my finger is over it. Then, when my finger leaves the button and enters the second button I need the second to activate and the first to deactivate.

任何意见将是极大的AP preciated!

Any advice would be greatly appreciated!

推荐答案

您也可以使用功能的touchesBegan。有了这个功能,您可以轻松地说会发生什么,如果一个按钮(或多个按钮)正在pressed /感动。

You can also use the function touchesBegan. With this function you can easily say what would happen if a button (or multiple buttons) are being pressed/touched.

code应该是这样的:

Code should look like:

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

    if(touch == YourButton){
         //so some stuff after touching the button

    }
}

不要忘了decare在你的.h IBOutlet中像*的UIButton将用作MyButton按钮;

Don't forget to decare the button in your .h like IBOutlet UIButton * MyButton;

这篇关于如何当用户在iPhone上对他们滑出自己的手指创造出被激活按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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