UIView background color affects touches in iOS 5(UIView 背景颜色影响 iOS 5 中的触摸)
问题描述
我有一个在 iOS 4 中工作的带有子类触摸响应的自定义视图.在 iOS 5 上,当沿着视图的底部边缘触摸时,这些触摸根本不会响应,如果视图的背景颜色设置为 clearColor
.
I had a custom view with subclassed touch responses that was working in iOS 4. On iOS 5, these touches would not respond at all when touched along the bottom edge of the view, if the view's background color was set to clearColor
.
我无法追踪到这一点,但有谁知道 iOS 5 是否改变了视图根据透明背景响应触摸的方式?
I have not been able to track this down, but does anyone know if iOS 5 changed the way views respond to touches depending on a transparent background?
除了将背景颜色设置为像 orangeColor
这样的任何不透明颜色之外,我无法对代码进行任何更改,并且视图会完全响应.
I can make no changes to the code other than set the background color to any opaque color like orangeColor
and the view fully responds.
请注意,该问题不会影响视图中其他地方的触摸;仅沿底部边缘,添加到视图的最后一个子视图下方的任何位置;在查看没有内容的视图区域时,可能会为了触摸而将清晰的背景视为视图不存在.改变颜色,视图有内容"并且触摸工作!
Note the issue does not affect touches elsewhere in the view; only along the bottom edge, anywhere below the last subview added to the view; presumably a clear background is treated as if the view does not exist for the sake of touches when looking at an area of the view that has no content. Change the color, the view has "content" and the touches work!
推荐答案
不要使用[UIColor clearColor]
,试试这个:
[view setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]];
注意:当 alpha
低于 0.1
时,UIView
不会响应触摸事件.[UIColor clearColor]
将 alpha
设置为 0.0
,因此您不会收到触摸事件.按照上面的方法,就可以在透明视图上接收到触摸事件了.
NOTE: A UIView
does not respond to touch events when the alpha
is anything below 0.1
. [UIColor clearColor]
sets an alpha
to 0.0
, so you won't get the touch events. Following the above method, you can receive the touch events on a transparent view.
这篇关于UIView 背景颜色影响 iOS 5 中的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIView 背景颜色影响 iOS 5 中的触摸


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01