拖动到值标签 [英] Dragging values onto labels

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

问题描述

我有一个iPad应用程序我正在开发的地方,当用户点击一个按钮产生一个随机数,它出现在标签上的按钮,这样用户认为价值上的按钮。用户可以再次单击该按钮来获得另一个随机号码,如果他们想要的。

I have an iPad app I'm developing where a random number is generated when a user clicks a button, and it appears on a label over the button, so the user thinks that value is on the button. The user can click the button again to get another random number if they want it.

有没有办法对我来说,允许用户从源拖动的数(比如,一个标签)到另一个标签 - 这样,而不是说有一个用户点击按钮的次数来获得一些他们愿意,他们可以简单地从菜单在标签上拖动它。

Is there a way for me to allow a user to drag a number from a source (say, a label) to another label - so that instead of a user having to click the button a number of times to get the number they want, they can simply drag it from a 'menu' onto the label.

任何帮助将AP preciated

Any help would be appreciated

感谢

Baruugh

推荐答案

您需要自己处理触摸事件。子类的UILabel并覆盖其触及... 方法。

You need to handle touch events yourself. Subclass UILabel and override its touches... methods.

首先,你将更新标签的位置touchesMoved:withEvent:方法方法。在这种方法中,你有兴趣在上海华触摸位置,而不是在标签本身,所以做类似 [触摸anyObject] locationInView:self.superview]

First of all, you will update the position of the label in touchesMoved:withEvent: method. In this method you are interested in the touch location in the superview, not in the label itself, so do something like [[touches anyObject] locationInView:self.superview].

而在 touchesEnded:withEvent:方法方法,你会检查与按钮上的标签的位置,如果重叠,其值传递给按钮。这可以以许多方式来实现,但这里最好的做法国际海事组织是使一个委托模式。让谁管理的上海华是自定义的UILabel对象的委托视图控制器。发送消息给委托touchesEnded:withEvent:方法方法,并且让视图控制器处理场所的检查,以及按钮上的文字更新。

And in touchesEnded:withEvent: method, you will check the location of the label with the button, and if it overlaps, pass the value to the button. This can be achieved in many ways, but the best practice here IMO is to make a delegate pattern. Let the view controller who manages the superview be a delegate of the custom UILabel object. Send a message to the delegate in touchesEnded:withEvent: method, and let the view controller handles the location check, and the button text update.

这篇关于拖动到值标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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