当选择器操作是推送新的 UIViewController 时,UIButton 不显示突出显示
我有一个 iPhone / iOS 应用程序,其中存在 UIButtons(纯文本,带有文本标签;不使用自定义图形),按下该按钮时,会将新的 UIViewController 推送到 UINavigationController 堆栈上。
按钮间接出现在 UIScrollView 上;它们都是直接在另一个UIView上,该UIView是在运行时构造的,然后这个UIView被添加到UIScrollView中。
问题:当用户按下这些按钮之一时,在大多数情况下,尽管采取了正确的操作(正确的视图控制器被推入堆栈),但该按钮不会显示为突出显示。
如果我将按下检测设置为使用 TouchUpInside 而不是 TouchDown,那么如果用户按住按钮很短的时间(也许是半秒?),按钮会显示为突出显示,但使用 TouchDown 时它很少突出显示,并且在任何事件,我希望即使用户只是轻轻点击按钮,突出显示也会显示出来。
我研究了这个网站和其他网站来寻找答案,并尝试了我发现的解决类似问题的各种方法。最可能的答案似乎是将 UIScrollView 的“delaysContentTouches”属性设置为“否”,但这没有明显的效果我的应用程序的差异。事实上,我发现没有任何东西能够令人满意地回答这个问题。
有什么想法吗?...
I have an iPhone / iOS application in which there exist UIButtons (plain, with text labels; no custom graphics used) which, when pressed, push a new UIViewController onto the UINavigationController stack.
The buttons appear indirectly on a UIScrollView; they are all directly on another UIView, which is constructed at runtime, and then this UIView is added to the UIScrollView.
The problem: when a user presses one of these buttons, in most instances, the button does not show as highlighted, although the correct action is taken (the proper view controller is pushed onto the stack).
If I set the press detection to use TouchUpInside rather than TouchDown, then if the user holds the button pressed down for a short time (half a second, perhaps?) the button shows as highlighted, but using TouchDown it is rarely highlighted, and in any event, I would prefer that the highlight shows up even if the user just lightly taps the button.
I've researched this site and others for answers, and tried the various approaches that I found suggested for combating similar issues.. The most likely answer seemed to be setting the "delaysContentTouches" property to NO for the UIScrollView, but this made no discernable difference in my application. Indeed, nothing that I found satisfactorily answered the question.
Any ideas?...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,延迟是由 UIScrollView 尝试检测滚动手势引起的,是的,您可以通过将
delaysContentTouches
设置为 NO 来解决它。此外,您应该始终对 UIButton 使用UIControlEventTouchUpInside
而不是UIControlEventTouchDown
,因为这允许用户通过将手指拖离按钮更远来“改变主意”。Yes, the delay is caused by UIScrollView trying to detect a scrolling gesture, and yes, you can solve it by setting
delaysContentTouches
to NO. Moreover, you should always useUIControlEventTouchUpInside
rather thanUIControlEventTouchDown
with UIButton because that allows the user to "change her mind" by dragging the finger farther away from the button.