2016-10-04 98 views
1

我的问题是,我有2个图形动画一个接一个,但他们一起完成。 我想写一个完成块的方法,但或者我做错了什么,或者有另一种方法来做到这一点。完成块图形动画

动画是一个uiview,它移出屏幕(closeView)和viewcontroller关闭的默认动画。 我希望viewcontroller在关闭视图动画时关闭。

这是我做了什么

- (void)closeViewWithCompletion:(void (^) (BOOL finish))handler { 
    [self closeView]; 
    handler(YES); 
} 

-(void) closeView{ 
     [self.myview setFrame:CGRectMake(
              -self.myview.frame.size.width 
              , self.myview.frame.origin.y 
              , self.myview.frame.size.width 
              , self.view.frame.size.height 
             )]; 


     CATransition *animation = [CATransition animation]; 
     [animation setType:kCATransitionPush]; 
     [animation setSubtype:kCATransitionFromRight]; 
     [animation setDuration:.50]; 
     [animation setDelegate:self]; 
     [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
     CALayer *layer = [self.myview layer]; 
     [layer addAnimation:animation forKey:nil]; 

     [UIView animateWithDuration:0.5 animations:^{ 
      [greyMask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0]]; 
     } completion:^(BOOL finished) { 
      [greyMask removeFromSuperview]; 
     }]; 
} 

使用:

[vc closeViewWithCompletion:^(BOOL finish) { 
     [navController popViewControllerAnimated:true]; 
    } 
]; 
+0

显示您需要依次执行的动画代码。 – vaibhav

回答

1

拨打completionBlockhandler块后您的closeView动画完成。

- (void)closeViewWithCompletion:(void(^)(BOOL finish))handler { 

    //closeView Animation 
    [UIView animateWithDuration:duration delay:0 options: UIViewAnimationOptionCurveEaseOut animations:^{ 
     //code for close view animation 
    } completion:^(BOOL finished) { 
     handler(YES) //call your handler in completion block 
    }]; 
} 

[vc closeViewWithCompletion:^(BOOL finish) { 
    [self.navigationController popViewControllerAnimated:true]; 
}];