Apple的iOS人机交互设计指南中指出,按钮点击热区应不小于44x44pt,否则这个按钮就会让用户觉得“很难用”,因为明明点击上去了,却没有任何响应
为了发大按钮的可触范围,需要重写UIButton的- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;方法,改变按钮的可触范围。
1.使按钮的可触范围改变至44*44
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
CGRect bounds = self.bounds;
CGFloat width = 44.0f - bounds.size.width;
CGFloat height = 44.0f - bounds.size.height;
bounds = CGRectInset(bounds, - 0.5 * width, - 0.5 * height);//改变bounds的范围
return CGRectContainsPoint(bounds, point);//如果point 在 bounds 内,返回YES,否则返回NO
}

根据Apple的iOS人机交互设计指南,按钮的最小点击热区应为44x44pt。本文介绍了通过重写UIButton的`pointInside:withEvent:`方法来扩大小于44x44pt按钮的可触范围,确保用户能有效点击。提供两种实现方式,一种是将所有按钮的可触范围扩大到44x44pt,另一种仅扩大小于44x44pt的按钮。
最低0.47元/天 解锁文章
1210

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



