IOS solves the delay problem of UIButton clicking on the caton and

  • 2020-06-19 11:45:34
  • OfStack

preface

At the beginning, I thought there was something wrong with the code. The click event contained time-consuming code for the main thread of the card, but I found that this was not the case by cutting the code one by one.

The body of the

Unlike in the reference article, UIButton is not on UIScrollView or UITableView, but ViewController supports sliding back.

-- -- -- -- -- -- -- -- -- line, search for speculation in the problem solving -- -- -- -- -- -- -- -- --

Solution: There is no good way, ImageView plus UITapGestureRecognizer, and the click effect code :)


class UIImageViewEffect : UIImageView {

  var effectAlpha: CGFloat = 0.5


  override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    alpha = effectAlpha
  }

  override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
    self.alpha = 1
  }

  override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    self.alpha = 1
  }
}

Above is to solve the problem of IOS UIButton, UIButton in need of a friend reference.


Related articles: