Thursday, June 6, 2013

Making something appear and disappear nicely in iOS6.0 with ARC

All UIViews have a hidden option that you can use to hide items when you don't want the user to see them but instead of just getting rid of them, you can make them appear and disappear nicely;

-(void)FlipView:(UIView*)flipView{

    if (flipView.hidden == FALSE){
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:flipView cache:NO];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1.0];
        [UIView commitAnimations];
        
        flipView.hidden = TRUE;
    }else{
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:flipView cache:NO];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1.0];
        [UIView commitAnimations];

        flipView.hidden = FALSE;
    }

}

The option UIViewAnimationTransitionCurlUp can be instead replaced with UIViewAnimationTransitionCurlDownUIViewAnimationTransitionFlipFromLeft, or UIViewAnimationTransitionFlipFromRight

No comments:

Post a Comment