PGメモ

非エンジニアの記録

ボタンに長押しを実装する [Xcode6 / Swift]

import UIKit

class ViewController: UIViewController {

  @IBOutlet var startBtn: UIView!

  override func viewDidLoad() {
    super.viewDidLoad()
    
    let myLongPressGesture = UILongPressGestureRecognizer(target: self, action: "pushStartBtn:")
    myLongPressGesture.minimumPressDuration = 0.1
    self.view.addGestureRecognizer(myLongPressGesture)
  }

  @IBAction func pushStartBtn(sender: UILongPressGestureRecognizer) {
    // todo
  }

}

こんな感じ