• swift 如何实现点击view后显示灰色背景


    有这样一种场景,当我们点击view的时候,需要过0.几秒显示一个灰色或者别的颜色的背景

    用button来实现,只有按下去的时候才会出现,往往在快速按下,快速抬起的时候是看不出这个变化的

    下边是解决方案

     1 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
     2         
     3         let touch = touches.first!
     4         let p = touch.locationInView(self.retweetBackgroundView)
     5         let insideRetweet = CGRectContainsPoint(self.retweetBackgroundView!.bounds ,p)
     6         
     7         if self.retweetBackgroundView?.hidden == false && insideRetweet {
     8             
     9             self.retweetBackgroundView!.performSelector("setBackgroundColor:", withObject: kWBCellHighlightColor, afterDelay: 0.15)
    10             self._touchRetweetView = true
    11         }else {
    12 
    13             self.contentView!.performSelector("setBackgroundColor:", withObject: kWBCellHighlightColor, afterDelay: 0.15)
    14             self._touchRetweetView = false
    15         }
    16 
    17     }
    18     
    19     override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    20         
    21         self.touchesRestoreBackgroundColor()
    22     }
    23     
    24     override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
    25         
    26         self.touchesRestoreBackgroundColor()
    27     }
    28     
    29     func touchesRestoreBackgroundColor() {
    30         NSObject.cancelPreviousPerformRequestsWithTarget(self.retweetBackgroundView!, selector: "setBackgroundColor:", object: kWBCellHighlightColor)
    31          NSObject.cancelPreviousPerformRequestsWithTarget(self.contentView!, selector: "setBackgroundColor:", object: kWBCellHighlightColor)
    32         self.retweetBackgroundView!.backgroundColor = UIColor.whiteColor()
    33         self.contentView.backgroundColor = kWBCellInnerViewColor
    34     }
  • 相关阅读:
    人脸识别数据库
    美赛
    排序算法
    个人作业——软件工程实践总结作业
    事后诸葛亮(团队)
    个人作业——软件产品案例分析
    Alpha冲刺总结
    Alpha冲刺——Day2
    Alpha冲刺——Day1
    I Know Alpha冲刺随笔集
  • 原文地址:https://www.cnblogs.com/machao/p/5127098.html
Copyright © 2020-2023  润新知