带 Alpha 的 UISlider 动画

发布于 2024-12-03 01:13:21 字数 973 浏览 0 评论 0原文

我正在尝试使 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟花肆意 2024-12-10 01:13:21

我对此不确定......但也许按照以下方式编写代码可能会有所帮助。

[self setUserInteractionEnabled:NO];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

self.alpha = 0.5;
self.value = newValue;

[UIView commitAnimations];


我能想到的其他方法是重写 setValueAnimated 方法并更改 alfa

I am not sure about this...but maybe writing code following way may help.

[self setUserInteractionEnabled:NO];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

self.alpha = 0.5;
self.value = newValue;

[UIView commitAnimations];

OR
Other way I can think of is that you override setValueAnimated method and change alfa in that

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文