欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Swift 2.1 為 UIView 添加點(diǎn)擊事件和點(diǎn)擊效果

 更新時(shí)間:2016年07月22日 10:15:39   投稿:lqh  
本文主要介紹 Swift UIView,這里給大家提供代碼示例作為參考為UIView 添加點(diǎn)擊事件和點(diǎn)擊效果,希望能幫助IOS開(kāi)發(fā)的同學(xué)

前言

  UIView 不像 UIButton 加了點(diǎn)擊事件就會(huì)有點(diǎn)擊效果,體驗(yàn)要差不少,這里分別通過(guò)自定義和擴(kuò)展來(lái)實(shí)現(xiàn)類(lèi)似 UIButton 的效果。

正文

  一、為 UIView 添加點(diǎn)擊事件

extension UIView {

  func addOnClickListener(target: AnyObject, action: Selector) {
    let gr = UITapGestureRecognizer(target: target, action: action)
    gr.numberOfTapsRequired = 1
    userInteractionEnabled = true
    addGestureRecognizer(gr)
  }

}

        二、為 UIView 添加點(diǎn)擊效果

class UIViewEffect : UIView {

  override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    backgroundColor = UIColor.groupTableViewBackgroundColor()
  }

  override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
    UIView.animateWithDuration(0.15, animations: { () -> Void in
      self.backgroundColor = UIColor.clearColor()
    })
  }

  override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    UIView.animateWithDuration(0.15, animations: { () -> Void in
      self.backgroundColor = UIColor.clearColor()
    })
  }
}

 這里大家可以換成自己的點(diǎn)擊效果,如果是 UIImageView 可以換成點(diǎn)擊變更透明度。

相關(guān)文章

最新評(píng)論