iOS 7自定义键盘UIView触摸事件在底行延迟
<p><p>这是一个奇怪的..</p>
<p>我有一个 <code>UIView</code> xib 文件,如下所示:</p>
<p> <img src="/image/NjcUc.png" alt="enter image description here"/> </p>
<p>我已将每个 <code>UIButton</code> <code>touchDown</code> 和 <code>touchUpInside</code> 事件连接到两个 <code>IBAction</code> 方法:</p>
<pre><code>- (IBAction)touchUpInside:(id)sender
{
NSLog(@"touch up inside");
if (((UIButton *)sender == _enter) | ((UIButton *)sender == _back)) {
[(UIButton *)sender setBackgroundColor:_color2];
}
else {
[(UIButton *)sender setBackgroundColor:_color1];
}
}
- (IBAction)touchDown:(id)sender
{
NSLog(@"touch down");
[(UIButton *)sender setBackgroundColor:_color2];
}
</code></pre>
<p>除了最底部的 <code>UIButton</code> 行之外,一切正常,这是奇怪的部分:</p>
<p><code>touch down</code> 事件被触发,但按钮必须按住 0.5 秒才能改变背景颜色,而其他按钮是瞬时的。</p>
<p>它只发生在 <code>UIButton</code> 的最底部一行,因为我尝试使用按钮 @back、0、@enter 切换按钮 7、8、9,如下所示:</p>
<p> <img src="/image/lZ2uA.png" alt="It is always the bottom-most row of <code>UIButton</code>'s that show the touchDown delay"/> </p>
<p>我在 Interface Builder 中检查了所有 <code>UIButton</code> 属性都是相同的,并且我已经尝试移动 <code>UIButton</code> 的对象顺序,如您所见图片的左侧,我已经没有想法了。基本上奇怪的是 <code>UIControl</code> 行为根据其在父 View 上的位置而有所不同...</p>
<p>更新:我使父 <code>UIView</code> 高度值足够大,以至于最后一行下方有 50 个空闲像素,并且 <code>UIButton</code> 现在可以正常工作。我现在能想到的唯一原因是 <code>UITabBar</code> 下面有 2 个 ViewController 级别。即使这样也没有意义。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p> <a href="https://developer.apple.com/library/ios/documentation/userexperience/conceptual/transitionguide/Scoping.html" rel="noreferrer noopener nofollow">The document</a>说:</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>这里有一个解决方案:
<a href="https://stackoverflow.com/questions/23046539/uibutton-fails-to-properly-register-touch-in-bottom-region-of-iphone-screen" rel="noreferrer noopener nofollow">UIButton fails to properly register touch in bottom region of iPhone screen</a> </p>
<p>但是,就你而言,我认为你应该在 <code>UIResponder</code> 中使用 <code>inputView</code>。<br/>
见:<a href="https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html</a> </p>
<p><code>inputView</code> 不受该问题的影响。</p></p>
<p style="font-size: 20px;">关于iOS 7自定义键盘UIView触摸事件在底行延迟,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25052832/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25052832/
</a>
</p>
页:
[1]