提示框(UIAlertAction)、点击事件(UITapGestureRecognizer)

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)
    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 有两种方法: 1.js方式,这种方法可以实现,但是点击后鼠标不能在其他地方点击,否则内容会变成提示文字,适合输入后...
    f675b1a02698阅读 4,908评论 0 0
  • Wang99阅读 3,550评论 0 0
  • 今天测试提了个bug:"在魅族mx4 pro"上发现,对话框点击事件无效搜索了一下好像没有人遇到过这个问题,就自己...
    pdog18阅读 3,644评论 0 0
  • 最近遇到一些jvm上的问题,查了一些资料,基本解决问题了,下面这些文章写得非常好,值得仔细读一读。 垃圾收集简介 ...
    techhow阅读 1,463评论 0 0
  • 《心理罪》系列第一次出现在我的视野应该是在2015年,网剧心理罪第一季上映,我开始对心理画像有了模糊的认识,进而产...
    overlap阅读 5,712评论 0 2

友情链接更多精彩内容