Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
UISwitch当您点击非活动侧时,有没有办法阻止切换状态?我想要一个强制执行故意“滑动”操作的控件,以防止用户意外单击它。我环顾四周,但没有找到任何删除即时切换的设置。
UISwitch
UISwitch 是 UIResponder 的子级。因此,您可以尝试使用touchesBegan:withEvent:,touchesMoved:withEvent:和之类的方法touchesEnded:withEvent:来检测用户操作。
touchesBegan:withEvent:
touchesMoved:withEvent:
touchesEnded:withEvent:
这个想法是在用户开始触摸时将一些标志设置为“不允许更改”状态。根据触摸坐标更改它 - 例如,如果用户将触摸向右移动超过 25 个像素,则将状态更改为“允许更改”。并在触摸结束时进行真正的更改,具体取决于最终标志的状态。