简体   繁体   English

延迟按钮的突出显示状态

[英]Delay of button's highlighted state

I have the issue in two completely different situations, which makes it really weird. 我在两个完全不同的情况下遇到了这个问题,这让人很奇怪。

  1. Situation: A UIButton in as a subView of another UIView. 情况:UIButton作为另一个UIView的子视图。
  2. Situation: UIBarButtonItem's in a UIToolBar. 情况:UIBarButtonItem位于UIToolBar中。

In both situations the buttons's are only highlighted after a slight delay, approximately .5 - 1 second. 在这两种情况下,按钮仅在稍微延迟后突出显示,约为0.5-1秒。 Definitely to long to highlight the view when tapping it normally. 绝对要在正常点击时突出显示视图。 They both work perfectly on the simulator, but not on a real device (I have an iPhone 5s with iOS 7.0.4). 它们都可以在模拟器上完美运行,但不能在真实设备上运行(我有一个带有iOS 7.0.4的iPhone 5s)。

What I tried 我尝试了什么
Setting the zPosition to the highest value (MAXFLOAT) of these views, to ensure nothing is blocking the tap. 将zPosition设置为这些视图的最高值(MAXFLOAT),以确保没有任何东西阻止点击。
Explicitly enabling the highlighting. 明确启用突出显示。

Both obviously doesn't worked. 两者显然都没有用。

Edit: Still not solved. 编辑:仍未解决。

This can happen if the buttons are placed close to the bottom edge of the display. 如果按钮靠近显示屏的底边放置,则会发生这种情况。 There's a conflict with the system edge gesture to present Control Center (or App Switcher on iPhone X and iPad). 系统边缘手势与控制中心(或iPhone X和iPad上的App Switcher)存在冲突。 It delays touches for your buttons until it's determined the user isn't performing a system gesture. 它会延迟按钮的触摸,直到确定用户没有执行系统手势。

If you would like, you can tell the system to give precedence to your gestures over the system gestures. 如果您愿意,可以告诉系统优先考虑系统手势的手势。

override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
    return .bottom
}

Do note however that this will require the user swipe twice to activate the system gesture. 但请注意,这将要求用户滑动两次以激活系统手势。

I know it's been a long time, but I just faced a similar issue: 我知道这已经很久了,但我刚遇到了类似的问题:

  • My UIButton is a subview of UINavigationController.view 我的UIButtonUINavigationController.view的子视图
  • There's no delay on the simulator 模拟器没有延迟
  • But there's a delay to show the highlight on the device 但是有一个延迟,以显示设备上的亮点

I just found out that it only happens if I run the app from Xcode. 我发现只有从Xcode运行应用程序才会发生这种情况。 If I disconnect the device and open the app from it's icon everything works just fine. 如果我断开设备并从它的图标打开应用程序一切正常。

I hope it helps. 我希望它有所帮助。

Are the UIButtons inside a UIScrollView ? UIBcroll在UIScrollView中吗? If they are, the delay is there so the scrollview can determine whether the touch is for scrolling or it should be passed on to the subview. 如果是,则延迟在那里,因此滚动视图可以确定触摸是用于滚动还是应该传递到子视图。

See also UIButton touch is delayed when in UIScrollView 另请参见UIScrollView中的UIButton触摸延迟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS 7上UIButton突出状态的延迟 - Delay of UIButton's highlighted state on iOS 7 是否可以在UIScrollView中删除UIButton突出显示状态的延迟? - Is it possible to remove the delay of UIButton's highlighted state inside a UIScrollView? 根据按钮的突出显示状态更改标签文本的颜色 - change labeltext color depending on the highlighted state of button 按钮离开突出显示状态时的调用方法 - Call method when Button leaves Highlighted State 如何在 NativeScript 中为 iOS 更改突出显示状态的按钮文本颜色? - How to change Button text color in highlighted state for iOS in NativeScript? UIButton:背景图像设置突出显示按钮状态时出现问题? - UIButton : Background Image setting Issue when button state is highlighted? UITableViewCell 的默认选中/高亮 state 的颜色值是多少? - What is the color value of UITableViewCell’s default selected/highlighted state? UISegmentedControl边框/突出显示状态 - UISegmentedControl Borders/Highlighted State 为什么将UILabel设置在情节提要中时松开突出显示状态? - Why does UILabel looses it's highlighted state when it's set in story board? 如何清除UIBarButtonItem的标题标签在突出显示状态下变暗 - How to get rid of UIBarButtonItem's title label becomes dark on highlighted state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM