views:

39

answers:

2

I am a little puzzled why the following is not working, button_ONE does a nice fade, but pressing button_TWO just snaps the color to black with no fade.

// FADES OUT OVER 1.5 Secs
- (IBAction)button_ONE:(id)sender {
    NSLog(@"FADE ALPHA");
    [textField_TOP_01 setAlpha:1.0];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [textField_TOP_01 setAlpha:0.0];
    [UIView commitAnimations];
}

.

// IMMEDIATELY CHANGES TO BLACK
- (IBAction)button_TWO:(id)sender {
    NSLog(@"FADE COLOR");
    [textField_TOP_02 setTextColor:[UIColor redColor]];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [textField_TOP_02 setTextColor:[UIColor blackColor]];
    [UIView commitAnimations];
}

Also this is using a subclass of UIViewController, I am also a little puzzled as to what UIView is refering / how its working.

many thanks

Gary

+1  A: 

The textColor property of a UILabel is not an animatable property, so it's changes are not done as part of the animation.

The animation related methods on UIView are class methods rather than instance methods, so you call them on the class directly. Check out the documentation on 'method type identifiers' at http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/.

Robot K
Ah I see, that would explain it, much appreciated. Can I ask where it tells you that textColor is not animatable? Just curious as I can't see it in the docs for UITextField?
fuzzygoat
Search the documentation for UIView (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html) for `animated` to see properties that are animatable. I'm trying to think of an easy alternative, but the best I can come up with is to animate the alpha to 0.0, change the text color, and then animate the alpha back to 1.1. However that may not be the effect you're looking for.
Robot K
Hi, thank you, changing the alpha will work fine for what I need, in fact its probably better. I was looking at using animateWithDuraction:animations: but went with this method as I would prefer things to work pre-4.0.
fuzzygoat
1.1 -> 1.0. in the above comment.
Robot K
+1  A: 

Add the following in between your beginAnimations:context: and commitAnimations statements:

[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:textField_TOP_02 cache:YES];
rpetrich