利用控件Tap gesture 和 UIAlertView + UIActionSheet
手勢(shì)識(shí)別器 單擊 雙擊(按住option)
//三種觸發(fā)動(dòng)作 一是addtag 二是代理方法 三是手勢(shì)
//手勢(shì)識(shí)別器
//UIGestureRecognizer
//識(shí)別在某一個(gè)視圖上的操作
let tap = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
self.view.addGestureRecognizer(tap)
手勢(shì)識(shí)別器的觸發(fā)事件
彈出了警告提示界面 為了讓用戶(hù)能夠跳到其他界面 加入了UIAlertAction
func didTap(sender: UITapGestureRecognizer) {
//返回參考self.view的坐標(biāo)
let location = sender.locationInView(self.view)
print("tap: \(location)")
//UIAlertView + UIActionSheet
//三個(gè)以上用列表.ActionSheet
let alertCtrl = UIAlertController(title: "警告", message: "不要亂點(diǎn)", preferredStyle: .Alert)
alertCtrl.addTextFieldWithConfigurationHandler { (textField) in
textField.placeholder = "姓名"
textField.keyboardType = .NumberPad
}
//彈出的提示界面里面包含的控制選擇
let action1 = UIAlertAction(title: "canle", style: .Cancel) { (action) in
}
let action2 = UIAlertAction(title: "ok", style: .Default){ (action) in
let textFile = alertCtrl.textFields![0]
print(textFile.text)
}
alertCtrl.addAction(action1)
alertCtrl.addAction(action2)
//手勢(shì)點(diǎn)擊后彈出一個(gè)提示界面
self.presentViewController(alertCtrl, animated: true, completion: nil)
}