几周之前发现的问题,当点击一个按钮并快速返回时,会发现点击的这个按钮左上会出现一个蓝色块,并快速消失,如图所示:
刚开始并不知道是什么原因,也无从下手,只能检查自己的代码,但前两天终于发现了问题的关键,原因是为了防止用户快速重复点击一个按钮,我用了类似下面的处理方式:
func changeButtonSelected(sender: UIButton) {
sender.selected = false;
}
func btnClicked(sender: UIButton) {
if (sender.selected == true) {
return;
}
sender.selected = true;
self.performSelector(#selector(changeButtonSelected(_:)), withObject: sender, afterDelay: 1.0);
// do anything you want after change sender selected
}
如果有需要限制用户点击的也不妨这么做,类似的还可以防止用户连续快速点击同一个UITableViewCell等等,我这篇文章也写过。
回到主题,这个蓝色块是怎么出现的呢,当这个UIButton的selected为true的时候,这个蓝色块就出现了,反之,蓝色块又消失了,原来这个按钮的type是system,确实没有注意到,当UIbutton的type是system、并且selected为true的时候,这个按钮会有一个蓝色块,这个小细节。。。改就非常好改了,改为Custom类型即可。
Let me know if this solved your issue.
2064

被折叠的 条评论
为什么被折叠?



