我在使用UIButton
操作和touchesmoved
时遇到问题。场景是,当我将手指拖过一系列按钮时,应该调用它的动作。我也可以单独触摸按钮。
我使用touchesmoved
方法找出uibutton上的触摸点以触发其动作。这种方法的问题是,当我点击视图中的某个地方并将手指移到按钮上时,一切正常,但如果我开始触摸UIButton本身,touchesmoved
方法就不会被调用。
答案 0 :(得分:3)
下面的检查对您有所帮助。
Handling touch events for UIButtons in iPhone
答案 1 :(得分:0)
如果您不需要知道触摸的确切位置,只需在它们上面滑动,就可以向其添加目标并使用许多UIControlEvent中的一个,如UIControlEventTouchDragInside等。
这是直接来自UIControl.h
enum {
UIControlEventTouchDown = 1 << 0, // on all touch downs
UIControlEventTouchDownRepeat = 1 << 1, // on multiple touchdowns (tap count > 1)
UIControlEventTouchDragInside = 1 << 2,
UIControlEventTouchDragOutside = 1 << 3,
UIControlEventTouchDragEnter = 1 << 4,
UIControlEventTouchDragExit = 1 << 5,
UIControlEventTouchUpInside = 1 << 6,
UIControlEventTouchUpOutside = 1 << 7,
UIControlEventTouchCancel = 1 << 8,
UIControlEventValueChanged = 1 << 12, // sliders, etc.
UIControlEventEditingDidBegin = 1 << 16, // UITextField
UIControlEventEditingChanged = 1 << 17,
UIControlEventEditingDidEnd = 1 << 18,
UIControlEventEditingDidEndOnExit = 1 << 19, // 'return key' ending editing
UIControlEventAllTouchEvents = 0x00000FFF, // for touch events
UIControlEventAllEditingEvents = 0x000F0000, // for UITextField
UIControlEventApplicationReserved = 0x0F000000, // range available for application use
UIControlEventSystemReserved = 0xF0000000, // range reserved for internal framework use
UIControlEventAllEvents = 0xFFFFFFFF
};
typedef NSUInteger UIControlEvents;