0

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.

yuji
  • 16,695
  • 4
  • 63
  • 64
chmod
  • 3
  • 2

1 Answers1

0

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

Mohammad
  • 1,636
  • 1
  • 13
  • 17
  • hmm. That didn't work, it seems that changing the value of the slider automatically changes its alpha to 1 every time. – chmod Sep 04 '11 at 17:32
  • The slider's value will change, but the alpha will remain at 1. – chmod Sep 05 '11 at 14:28