class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//手势识别器
//UIGestureRecognizer
//识别在某一个视图上的操作
let tap = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
self.view.addGestureRecognizer(tap)
}
func didTap(sender: UITapGestureRecognizer) {
//返回参考self.view的坐标
let location = sender.locationInView(self.view)
print("tap: \(location)")
//UIAlertView + UIActionSheet
let alertCtrl = UIAlertController(title: "警告", message: "不要乱点", preferredStyle: .ActionSheet)
let action01 = UIAlertAction(title: "OK", style: .Default) { (action) in
print("OK")
}
let action02 = UIAlertAction(title: "Cancel", style: .Destructive) { (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)
}
}
PKHUD
func didTap(sender: UITapGestureRecognizer){
let url = NSURL(string: "https://github.com")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) { (data, response, error) in
dispatch_async(dispatch_get_main_queue(), {
HUD.hide()
HUD.flash(.Success, delay: 2, completion: nil)
})
}
task.resume()
HUD.show(.SystemActivity)
}