6

次の条件でメソッドをトリガーするボタンが必要です。

  • ユーザーがボタンをタップしたとき
  • ユーザーがボタンを押して、ボタンの領域から指をドラッグしたとき
  • ユーザーがボタンの領域外からボタンの領域内に指をドラッグしたとき

基本的に、ボタンの任意の部分がタッチされたときはいつでも、タッチの起源に関係なく、メソッドをトリガーしたいのですが、UIButton プロパティなどを操作してこれを実現したいと考えていますtouchedUpInside

提案をありがとう!

4

3 に答える 3

3

それにかんする:

  • ユーザーがボタンを押して、ボタンの領域から指をドラッグしたとき

私は最近、似たようなことをしました。ここにSwiftの私のコードがあります。

(この例では、次のように UIButton をサブクラス化しました。class FadingButton: UIButton)

...

// The user tapped the button and then moved the finger around.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesMoved(touches, with: event)

    // Get the point to which the finger moved
    if let point: CGPoint = touches.first?.location(in: self) {

        // If the finger was dragged outside of the button...
        if ((point.x < 0 || point.x > bounds.width) ||
            (point.y < 0 || point.y > bounds.height)) {

            // Do whatever you need here
        }
    }
}
...

誰かの役に立てば幸いです。

于 2014-11-15T05:15:34.473 に答える
2

などのメソッドを-(IBAction)btnTap作成し、これらのプロパティに接続します

  • ユーザーがボタンをタップしたとき。-Touch Downこれにはメソッドを使用します
  • ユーザーがボタンを押してボタンの領域から指をドラッグしたとき -Touch Up Insideこの目的で使用
  • ユーザーがボタンの領域の外側からボタンの内側に指をドラッグすると、Touch Drag Inside
于 2013-06-13T07:35:07.010 に答える