import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 手勢(shì)識(shí)別器
// UIGestureRecognizer
// 識(shí)別在某一個(gè)視圖上的操作
// 瞬間觸發(fā):作用時(shí)間短,位移相對(duì)小,一般只會(huì)觸發(fā)一次
// tap/swipe
// 持續(xù)觸發(fā):作用時(shí)間長(zhǎng),位移相對(duì)大,會(huì)定時(shí)或相隔一段距離觸發(fā)
// pinch/rotato/long press/pan
// 點(diǎn)擊
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 //滑向某個(gè)方向
self.view.addGestureRecognizer(leftSwipe)
}
func didSwipe(sender: UISwipeGestureRecognizer){
print("left")
}
func didTap(sender: UITapGestureRecognizer) {
//返回值是參數(shù)坐標(biāo)
let location = sender.locationInView(self.view)
print("tap:\(location)")
//UIAlertView + UIActionSheet
let alertCtrl = UIAlertController(title: "警告", message: "不要亂點(diǎn)", preferredStyle: .Alert) //如果使用.ActionSheet,提示欄從下方彈上來(lái)
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)旋轉(zhuǎn)某視圖
//HUD控件自己研究,非常實(shí)用,但是要注意“時(shí)機(jī)”