import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 手勢識別器
// UIGestureRecognizer
// 識別在某一個視圖上的操作
// 瞬間觸發:作用時間短,位移相對小,一般只會觸發一次
// tap/swipe
// 持續觸發:作用時間長,位移相對大,會定時或相隔一段距離觸發
// pinch/rotato/long press/pan
// 點擊
let tap = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
self.view.addGestureRecognizer(tap)
// pinch 捏合
let up = UIPinchGestureRecognizer(target: self, action: #selector(didUp(_:)))
self.view.addGestureRecognizer(up)
let se = UIScreenEdgePanGestureRecognizer(target: self, action:#selector(didSe(_:)))
self.view.addGestureRecognizer(se)
let leftSwipe = UISwipeGestureRecognizer(target: self, action:#selector(didSwipe(_:)))
leftSwipe.direction = .Left //滑向某個方向
self.view.addGestureRecognizer(leftSwipe)
}
func didSwipe(sender: UISwipeGestureRecognizer){
print("left")
}
func didTap(sender: UITapGestureRecognizer) {
//返回值是參數坐標
let location = sender.locationInView(self.view)
print("tap:\(location)")
//UIAlertView + UIActionSheet
let alertCtrl = UIAlertController(title: "警告", message: "不要亂點", preferredStyle: .Alert) //如果使用.ActionSheet,提示欄從下方彈上來
let action01 = UIAlertAction(title: "OK", style: .Default) {
(action) in
print("OK")
}
let action02 = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
print("Cancel")
}
let action03 = UIAlertAction(title: "3", style: .Default) { (action) in
print("3")
}
alertCtrl.addAction(action01)
alertCtrl.addAction(action02)
alertCtrl.addAction(action03)
self.presentViewController(alertCtrl, animated: true, completion: nil)
}
// 捏合
func didUp(sender: UIPinchGestureRecognizer) {
let actionC1 = UIAlertController(title: "hehe", message: "HAHA", preferredStyle: .Alert)
let action01 = UIAlertAction(title: "OK", style: .Default) {
(action) in
print("OK")
}
actionC1.addAction(action01)
self.presentViewController(actionC1, animated: true, completion: nil)
}
func didSe(sender: UIPinchGestureRecognizer) {
let actionC2 = UIAlertController(title: "???", message: "!!!", preferredStyle: .Alert)
let action02 = UIAlertAction(title: "OK", style: .Default) {
(action) in
print("OK")
}
actionC2.addAction(action02)
self.presentViewController(actionC2, animated: true, completion: nil)
}
}
// * xxxView.transform = CGaffineTransformMakeRotation(CGFloat(M_PI_2)旋轉某視圖
//HUD控件自己研究,非常實用,但是要注意“時機”