2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Swift PanGesture

Posted at

UIPanGestureメモ

ドラッグアンドドラップ等のリッチなスマホ操作を実現できる。継承もとはUIGestureRecoginizer

要素

var maximumNumberOfTouches: Int
//ジェスチャ-を認識するためにビューに触れることができる指の最大数。
var minimumNumberOfTouches: Int
//ジェスチャ-を認識するためにビューに触れることができる指の最小数。
func translation(in: UIView?) -> CGPoint
//これで移動量を取れる
func setTranslation(CGPoint, in: UIView?)
指定したビューの座標に移動値を設定する
func velocity(in: UIView?) -> CGPoint
指定されたビューの座標でパンジェスチャの速度を返す
UIPanGestureRecognizer().state.began,changed,ended,でgestureの状態で条件分岐する

   let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGesture))
        view.addGestureRecognizer(panGesture)

@objc private func panGesture(gesture:UIPanGestureRecognizer) {
        let move = gesture.translation(in: view)

 if gesture.state == .began {//始まったら

}
 else if gesture.state == .changed{//ドラッグアンドドラッグアンドしている最中
//ここでmove.y,move.xなどで条件分岐するとアニメーションが豊かになる。
}
 else if gesture.state == .ended{//終わったら
}


}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?