UIView背景颜色影响iOS 5中的触摸 [英] UIView background color affects touches in iOS 5

查看:79
本文介绍了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?

除了将背景颜色设置为任何不透明颜色之外,我不能对代码进行任何更改code> 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] ,试试这个:

Instead of using [UIColor clearColor], try using this:

[view setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]];

注意:A UIView alpha 低于 0.1 时,$ c>不响应触摸事件。 [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中的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆