2016-10-04 112 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]; 
}];