IOS 解决UIButton 点击卡顿/延迟的问题

2022-10-21

本文主要介绍 IOS UIButton, 这里给大家提供代码实例作为参考,解决 UIButton 点击卡顿或者延迟问题,在开发 IOS 项目的小伙伴如果遇到这样的问题可以参考下

前言

  一开始还以为代码写的有问题,点击事件里面有比较耗时卡主线程的代码,逐一删减代码发现并不是这么回事。

正文

  和参考文章里说的情况不完全相同,UIButton 并没有放在 UIScrollView 或 UITableView 上,但是 ViewController 是支持滑动返回的。

 ——————————————————华丽的分割线,搜索猜测解题中——————————————————

  解决办法:也没什么好办法,换成 ImageView 加 UITapGestureRecognizer 吧,另外奉上点击效果代码 🙂

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

以上就是解决IOS UIButton 出现卡顿的问题,有需要的朋友参考下。

您可能感兴趣的文章:

  • iOS UIButton 点击无响应的解决办法
  • iOS中给自定义tabBar的按钮添加点击放大缩小的动画效果
  • iOS点击查看大图的动画效果
  • iOS自定义UIButton点击动画特效

《IOS 解决UIButton 点击卡顿/延迟的问题.doc》

下载本文的Word格式文档,以方便收藏与打印。