Welcome

首页 / 移动开发 / IOS / IOS 解决UIButton 点击卡顿/延迟的问题

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

正文
和参考文章里说的情况不完全相同,UIButton 并没有放在 UIScrollView 或 UITableView 上,但是 ViewController 是支持滑动返回的。
——————————————————华丽的分割线,搜索猜测解题中——————————————————
解决办法:也没什么好办法,换成 ImageView 加 UITapGestureRecognizer 吧,另外奉上点击效果代码 :)
class UIImageViewEffect : UIImageView {var effectAlpha: CGFloat = 0.5override 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 出现卡顿的问题,有需要的朋友参考下。