Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Category on View to animate subview like popup in iPhone sdk

    • 0
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 459
    Comment on it

    Hi Readers,

    In our app we usually make custom alerts which we need to animate at the time adding it on its superview.


    To achieve it with you custom view make a category like this :

    Put this code into your .h file of category named as UIView+AnimateView :

    @interface UIView (AnimateView)
    
    - (void)addSubviewWithBounce:(UIView*)subview;
    
    - (void)removeSubviewWithAnimation:(UIView*)subview;
    
    @end
    


    After that use following code in your .m file:

    @implementation UIView (AnimateView)
    
    - (void)addSubviewWithBounce:(UIView*)subview
    {
        subview.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
    
        [self addSubview:subview];
    
      [UIView animateWithDuration:0.3/1.5 animations:^{
        CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3/2 animations:^{
            subview.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.3/2 animations:^{
                subview.transform = CGAffineTransformIdentity;
            }];
        }];
    }];
    }
    
    - (void)removeSubviewWithAnimation:(UIView*)subview{
    
        subview.transform = CGAffineTransformIdentity;
    
        [UIView animateWithDuration:0.3/1.5 animations:^{
            subview.transform =  CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
        } completion:^(BOOL finished) {
            [subview removeFromSuperview];
        }];
    }
    
    @end
    


    Just import this category on any controller and call these function like :

    [self.view removeSubviewWithAnimation:subview];
    [self.view addSubviewWithBounce:subview];
    


    Thanks. Happy coding

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: