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控件自己研究,非常实用,但是要注意“时机”