Say I have a hidden view in Xcode for iOS. Now, when I set the view to not hidden (view.hidden=NO), how can I make it so that it now appears, but with animations?
-(void)showView{
[UIView beginAnimations: @"Fade Out" context:nil];
[UIView setAnimationDelay:0];
[UIView setAnimationDuration:.5];
//show your view with Fade animation lets say myView
[myView setHidden:FALSE];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(hideView) userInfo:nil repeats:YES];
[UIView commitAnimations];
}
-(void)hideView{
[UIView beginAnimations: @"Fade In" context:nil];
[UIView setAnimationDelay:0];
[UIView setAnimationDuration:.5];
//hide your view with Fad animation
[myView setHidden:TRUE];
[UIView commitAnimations];
}
OR you can try this way
self.yourView.alpha = 0.0;
[UIView beginAnimations:@"Fade-in" context:NULL];
[UIView setAnimationDuration:1.0];
self.yourView.alpha = 1.0;
[UIView commitAnimations];
If you want other animations than only fading then use this method
[UIView transitionWithView:_yourView duration:1.0 options:UIViewAnimationOptionTransitionCurlDown animations:^(void){
[_yourView setHidden:NO];
} completion:nil];
For a fade, you can adjust the alpha property of the view.
myView.alpha = 0;
[UIView animateWithDuration:0.5 animations:^{
myView.alpha = 1;
}];
That will apply a fade in over 0.5 seconds to the view myView
. Many UIView properties are animatable; you aren't just limited to alpha fades. You can change background colours, or even rotate and scale a view, with animation. If you need further control and advanced animation, you can then move into Core Animation - a much more complex animation framework.
What you probably want is not to set view.hidden
, but to set view.alpha
to 0
(corresponds to hidden = YES
) or 1 (hidden = NO
).
You can then use implicit animations to show the view, e.g
[UIView animateWithDuration:0.3 animations:^() {
view.alpha = 1.0;
}];