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

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

问题描述

当设置为0.5时,为什么UISlider视图忽略Alpha视图?



代码:

  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是完全不透明的。它接缝只发生与α0.5。已测试过其他UI控制器,并且它们按预期工作,alpha设置为0.5。



在真实设备上使用iOS 4.2进行转换,在模拟器中使用iOS 3.2和4.2。 p>

BTW如果有人好奇为什么,为什么我碰到这个问题,它的滑动方向垫配置一个益智游戏称为滑动

解决方案

正如你说的其他UI控制器使用0.5 alpha,应该没有区别 UISlider ,因为它们继承 UIView 类的instp / UIView / alpharel =nofollow> alpha 引用 opaque 属性(如果视图完全或部分透明,您应该始终将此属性的值设置为NO)。



如果真的有一个0.5值的错误,你可以简单地将起始透明度从0.4改为0.41 / 0.39 w / o任何可见差异:

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

最后,可以输出结果 alpha 值以检查它们是否为预期值,或输出(CGFloat)i 值以查看类型转换是否有问题。


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

Code:

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];
}

Result:

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.

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.

解决方案

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.

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;

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.

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

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