PGメモ

非エンジニアの記録

swiftでのコードのみで画面遷移

navigation controller使わずに遷移

let nextView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Detail") as UIViewController
self.presentViewController(nextView, animated: false, completion: nil)

navigation controller使ってに遷移

let storyboard = UIStoryboard(name: "Main", bundle:nil)
let pageViewController = storyboard.instantiateViewControllerWithIdentifier("Detail") as! DetailViewController
self.navigationController?.pushViewController(pageViewController, animated: true)

ボタンに長押しを実装する [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
  }

}

こんな感じ