滑入和滑出UIButton,并使其响应 [英] Slide to and from UIButtons and make them respond

查看:141
本文介绍了滑入和滑出UIButton,并使其响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Objective-C为iPhone创建一个半钢琴应用程序;它实际上是一个布局不同的MIDI控制器,但我仍在设计中.

I am creating a semi-piano app in Objective-C for iPhone; it's in fact a diffrent layout MIDI Controller, but I'm still working on the design.

我使用UIButton创建了所有键",并且希望能够滑动到它们或从它们滑动到其他UIButton.

I created all of the "keys" with UIButtons, and I want to be able to slide to them or from them to other UIButtons.

我之前阅读过所有类似的问题,但无法使其与touchesMoved一起使用, 因为只有在我不从UIButton拖动手指的情况下,它才能在视图中起作用.

I read all the similar questions before, but I couldn't make it to work with touchesMoved, Because it only worked from the view if I didn't drag the finger from a UIButton.

在此先感谢您,代码将不胜感激!

Thanks in advance, code will be appreciated!

推荐答案

您的按钮是在IB中创建的吗?在IB中连接按钮时的默认事件是内部向上触摸",这意味着当用户结束按钮内部的触摸(抬起手指)时,将触发该动作.钢琴键或类似键更适合在内部向下触摸"(用于首次按下)和触摸拖动输入"(用于当屏幕上已有的手指移入按钮)上触发.

Are your buttons created in IB? The default event when connecting buttons in IB is "touch up inside", which means the action is fired when the user ends a touch (lifts the finger) inside the button. A piano key or similar would be more appropriate to fire on the "touch down inside" (for the initial press) and the "touch drag enter" (for when a finger that is already on the screen moves into the button).

由于您以编程方式进行操作,因此可以按如下所述向按钮添加目标:

Since you are doing it programmatically, you can add targets to the buttons as described here:

只需在蒙版中包含您想要的事件即可.

Just include the events you want in the mask.

这篇关于滑入和滑出UIButton,并使其响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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