带 Alpha 的 UISlider 动画
我正在尝试使 UISliders 在无法使用时显示为灰色。
以下是我的 UISlider 子类中的代码:
- (void)setSymbol:(NSString *)s {
symbol = s;
float newValue = [[S76PresetManager sharedManager] getValueForKey:symbol];
[self setValue:newValue animated:YES];
if (symbol == @"" || symbol == @"e_none") {
// gray out the slider
[self setUserInteractionEnabled:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self setAlpha:0.5];
[UIView commitAnimations];
} else {
// reactivate the slider
[self setUserInteractionEnabled:YES];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self setAlpha:1.0];
[UIView commitAnimations];
}
}
如果滑块的符号属性设置为 @"" 或 @"e_none",它将使滑块变灰并导致其不可交互。然而,在某些情况下,行 [self setValue:newValueanimated:YES]
似乎“取消”了 setAlpha 动画。
有什么方法可以同时设置滑块的值并使用 UIView 动画更改其 alpha 值吗?
提前致谢。
I'm trying to make UISliders that animate to be greyed out when they cannot be used.
Here is the code in my UISlider subclass:
- (void)setSymbol:(NSString *)s {
symbol = s;
float newValue = [[S76PresetManager sharedManager] getValueForKey:symbol];
[self setValue:newValue animated:YES];
if (symbol == @"" || symbol == @"e_none") {
// gray out the slider
[self setUserInteractionEnabled:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self setAlpha:0.5];
[UIView commitAnimations];
} else {
// reactivate the slider
[self setUserInteractionEnabled:YES];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self setAlpha:1.0];
[UIView commitAnimations];
}
}
If the slider's symbol property is set to @"" or @"e_none", it will gray out the slider and cause it to not be interactive. However the line [self setValue:newValue animated:YES]
seems to "cancel out" the setAlpha animation in some cases.
Is there any way I can simultaneously set the value of the slider and change its alpha using UIView animations?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此不确定......但也许按照以下方式编写代码可能会有所帮助。
[self setUserInteractionEnabled:NO];
或
我能想到的其他方法是重写 setValueAnimated 方法并更改 alfa
I am not sure about this...but maybe writing code following way may help.
[self setUserInteractionEnabled:NO];
OR
Other way I can think of is that you override setValueAnimated method and change alfa in that