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 中的触摸
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
