2016-10-04 3 views
1

Mein Problem ist, dass ich 2 Grafikanimationen nacheinander habe, aber sie sind zusammen gemacht. Ich dachte, eine Methode mit Completion-Block zu schreiben, aber oder ich mache etwas falsch, oder es gibt einen anderen Weg, dies zu tun.Completion Block für Grafikanimation

Die Animation ist eine Ansicht, die sich aus dem Bildschirm (closeView) und der Standardanimation des Schließens des Viewcontrollers bewegt. Ich möchte den Viewcontroller geschlossen, wenn über die Animation der Ansicht ist.

Das ist, was ich

- (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]; 
     }]; 
} 

Gebrauch gemacht habe:

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

zeigen Sie beide der Animationscode, die Sie einzeln nacheinander ausführen müssen. – vaibhav

Antwort

1

rufen Sie Ihren handler Block in completionBlock nach dem closeView Animation, beendet.

- (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]; 
}];