【问题标题】:UISlider animation with alpha带有 alpha 的 UISlider 动画
【发布时间】:2011-09-04 15:24:43
【问题描述】:

我正在尝试让 UISlider 在无法使用时显示为灰色。

这是我的 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:newValue animated:YES] 行似乎“取消”了 setAlpha 动画。

有什么方法可以同时设置滑块的值并使用 UIView 动画更改其 alpha?

提前致谢。

【问题讨论】:

    标签: iphone animation uiview uislider


    【解决方案1】:

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

    [self setUserInteractionEnabled:NO];

    [UIView beginAnimations:nil context:nil];
    
    [UIView setAnimationDuration:0.5];
    
    self.alpha = 0.5;
    self.value = newValue;
    
    [UIView commitAnimations];
    

    或 我能想到的其他方法是您覆盖 setValueAnimated 方法并在其中更改 alfa

    【讨论】:

    • 嗯。这没有用,似乎每次更改滑块的值都会自动将其 alpha 更改为 1。
    • 滑块的值会改变,但 alpha 会保持在 1。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 2020-09-28
    • 1970-01-01
    相关资源
    最近更新 更多