Search code examples
iosanimationbuttonuiviewnavigationbar

How to add animation while changing the hidden mode of a uiview?


I want to add animation to a view while changing its hidden mode i.e

my_view.hidden=YES;

I have added a button in navigationbar. When we click on it the new view is set to be unhide. It draws at the upper of the navigation table.


Solution

  • Unfortunately, hidden is not a property that is animatable through UIView animations. I think your best bet may be to use one of the animations @Erik B suggested, or start dabbling with Core Animations which are much more powerful. Take a glance at the documentation for UIView animations and Core Animations.

    I achieved something like what your suggesting by using UIView animations to slide the new view from below another view. This made it appear like a drawer sliding out. If you want to do something like that, you need to intercept the touch up inside event and place the animation code there.

    - (IBAction)buttonClicked:(id)sender {
        [UIView animateWithDuration:0.5
                              delay:0.0 
                            options:UIViewAnimationCurveEaseOut
                         animations:^(void) {
                            self.myView.frame = /* set the frame here */
                         } 
                         completion:NULL];
    }