UISlider 设置为 0.5 时忽略 alpha [英] UISlider ignores alpha when set to 0.5

查看:17
本文介绍了UISlider 设置为 0.5 时忽略 alpha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 UISlider 视图设置为 0.5 时会忽略 alpha 视图?

Why does the UISlider view ignore the alpha view when set to 0.5?

代码:

for (int i = 0; i < 3; i++) {
  UISlider *slider = [[[UISlider alloc]
                       initWithFrame:CGRectMake(0, i * 30, 200, 30)]
                      autorelease];
  slider.alpha = 0.4 + (CGFloat)i / 10.0f;
  [window addSubview:slider];
}

结果:

滑块的 alpha 值为 0.4、0.5 和 0.6.正如你所看到的,中间的 0.5 是完全不透明的.它似乎只发生在 alpha 0.5 中.已经测试了其他 UI 控制器,并且在 alpha 设置为 0.5 时它们可以正常工作.

The sliders have alpha values 0.4, 0.5 and 0.6. And as you can see the middle one with 0.5 is completely opaque. It seams to only occur with alpha 0.5. Have tested other UI controllers and they work as expected with alpha is set to 0.5.

在真实设备上使用 iOS 4.2 以及在模拟器中使用 iOS 3.2 和 4.2 进行再现.

Reproduced with iOS 4.2 on real device and with iOS 3.2 and 4.2 in simulator.

顺便说一句,如果有人好奇我是如何以及为什么遇到这个问题的,那就是一个名为 滑溜.

BTW if someone curious how and why I hit this problem it's the sliding direction pad configuration for a puzzle game called Slippy.

推荐答案

正如你所说,其他 UI 控制器使用 0.5 alpha,与 UISlider 应该没有区别,因为它们继承了 alpha 属性 来自 UIView 类,并且引用了 opaque 属性 ("你应该总是设置如果视图完全或部分透明,则此属性为 NO").也许你可以尝试听从建议.

As you said that other UI controllers work with 0.5 alpha, there should be no difference with UISlider, since they inherit alpha property from UIView class and there is reference to the opaque property ("You should always set the value of this property to NO if the view is fully or partially transparent"). Maybe you can try to follow the advice.

如果确实存在 0.5 值的错误,您可以简单地将起始透明度从 0.4 更改为 0.41/0.39,而没有任何可见的差异:

If there's really a bug with 0.5 value, you can simply change your starting transparency from 0.4 to 0.41/0.39 w/o any visible difference:

slider.alpha = 0.41f + (CGFloat)i / 10.0f;

最后,您可以将生成的 alpha 值输出到某些标签以检查它们是否为预期值,或者输出 (CGFloat)i 值以查看是否有问题使用类型转换.

Finally, you can output the resulting alpha values to some labels to check if they are the expected ones or output the (CGFloat)i value to see if something wrong with type casting.

这篇关于UISlider 设置为 0.5 时忽略 alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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