OGeek|极客世界-中国程序员成长平台

标题: iOS 7自定义键盘UIView触摸事件在底行延迟 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:57
标题: iOS 7自定义键盘UIView触摸事件在底行延迟

这是一个奇怪的..

我有一个 UIView xib 文件,如下所示:

enter image description here

我已将每个 UIButton touchDowntouchUpInside 事件连接到两个 IBAction 方法:

- (IBAction)touchUpInsideid)sender
{
    NSLog(@"touch up inside");
    if (((UIButton *)sender == _enter) | ((UIButton *)sender == _back)) {
        [(UIButton *)sender setBackgroundColor:_color2];
    }
    else {
        [(UIButton *)sender setBackgroundColor:_color1];
    }
}

- (IBAction)touchDownid)sender
{
    NSLog(@"touch down");
    [(UIButton *)sender setBackgroundColor:_color2];
}

除了最底部的 UIButton 行之外,一切正常,这是奇怪的部分:

touch down 事件被触发,但按钮必须按住 0.5 秒才能改变背景颜色,而其他按钮是瞬时的。

它只发生在 UIButton 的最底部一行,因为我尝试使用按钮 @back、0、@enter 切换按钮 7、8、9,如下所示:

It is always the bottom-most row of <code>UIButton</code>'s that show the touchDown delay

我在 Interface Builder 中检查了所有 UIButton 属性都是相同的,并且我已经尝试移动 UIButton 的对象顺序,如您所见图片的左侧,我已经没有想法了。基本上奇怪的是 UIControl 行为根据其在父 View 上的位置而有所不同...

更新:我使父 UIView 高度值足够大,以至于最后一行下方有 50 个空闲像素,并且 UIButton 现在可以正常工作。我现在能想到的唯一原因是 UITabBar 下面有 2 个 View Controller 级别。即使这样也没有意义。



Best Answer-推荐答案


The document说:

Expect users to swipe up from the bottom of the screen to reveal Control Center. If iOS determines that a touch that begins at the bottom of the screen should reveal Control Center, it doesn’t deliver the gesture to the currently running app. If iOS determines that the touch should not reveal Control Center, the touch may be slightly delayed before it reaches the app.

这里有一个解决方案: UIButton fails to properly register touch in bottom region of iPhone screen

但是,就你而言,我认为你应该在 UIResponder 中使用 inputView
见:https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html

inputView 不受该问题的影响。

关于iOS 7自定义键盘UIView触摸事件在底行延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25052832/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4