views:

168

answers:

1

I try to fade the datepicker in and out smootly based on the switch setting on a view like below. I have tried the following in my view controller, but that just turns it on/off without animating.

-(IBAction)swithChanged:(id)sender{
    BOOL setting = dateSwitch.isOn;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    datePicker.alpha = (setting) ? 100 : 0;
    [UIView commitAnimations];
}

Also, is there a simple way to do other animations, like fly in from bottom/right/left on the datepicker (and other elements)?

alt text

+1  A: 

UIView's alpha (and CALayer's opacity, for that matter) is in the range [0; 1]. Setting it to 100 makes the animation duration 100 times shorter. Try 1 instead of 100.

For other types of animation set the view's center and/or bounds property inside a UIView animation block.

Costique