Ajouter une sous-vue avec animation UIAlertVIew, avec un effet de rebond

Comment donner une animation de style rebond ou pop up tout en ajoutant une sous-vue dans iOS? J'ai besoin de quelque chose de similaire au style d'apparence UIAlertView . Je sais qu'il existe plusieurs methods pour faire la même chose: mais je préfère utiliser basic [UIView animateWithDuration: ...]; bloquer ici, alors puis-je get de l'aide concernant la transform je devrais utiliser ici pour get l'effet pop-up?

Merci

Animation pour le style PopUp:

Rapide

 yourView.transform = CGAffineTransformMakeScale(0.01, 0.01) UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in yourView.transform = CGAffineTransformIdentity }, completion: {(finished: Bool) -> Void in // do something once the animation finishes, put it here }) 

Reverse Animation en hiding la same View

 yourView.transform = CGAffineTransformIdentity UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in yourView.transform = CGAffineTransformMakeScale(0.01, 0.01) }, completion: {(finished: Bool) -> Void in // do something once the animation finishes, put it here yourView.hidden = true }) 

Objectif c

 yourView.transform = CGAffineTransformMakeScale(0.01, 0.01); [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ yourView.transform = CGAffineTransformIdentity; } completion:^(BOOL finished){ // do something once the animation finishes, put it here }]; 

Reverse Animation en hiding la same View

  yourView.transform = CGAffineTransformIdentity; [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ yourView.transform = CGAffineTransformMakeScale(0.01, 0.01); } completion:^(BOOL finished){ yourView.hidden = YES; }]; 

Je l'avais déjà fait avant … vous pouvez get mon idée de ce code. Cela peut vous aider. si vous avez un problème, s'il vous plaît laissez-moi savoir. merci

 - (CGAffineTransform)transformForOrientation { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (orientation == UIInterfaceOrientationLandscapeLeft) { return CGAffineTransformMakeRotation(M_PI*1.5); } else if (orientation == UIInterfaceOrientationLandscapeRight) { return CGAffineTransformMakeRotation(M_PI/2); } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { return CGAffineTransformMakeRotation(-M_PI); } else { return CGAffineTransformIdentity; } } -(void)showCustomAlertView{ UIWindow *window = [UIApplication sharedApplication].keyWindow; //self (this view pop up like alert) [window addSubview:self]; self.transform = CGAffineTransformScale([self transformForOrientation], 0.001, 0.001); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/1.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)]; self.transform = CGAffineTransformScale([self transformForOrientation], 1.1, 1.1); [UIView commitAnimations]; } - (void)bounce1AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)]; self.transform = CGAffineTransformScale([self transformForOrientation], 0.9, 0.9); [UIView commitAnimations]; } - (void)bounce2AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/2]; self.transform = [self transformForOrientation]; [UIView commitAnimations]; } 

Essaye ça:

 self.popUpContainerView.alpha = 0; [UIView animateWithDuration:0.1 animations:^{self.popUpContainerView.alpha = 1.0;}]; CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; bounceAnimation.values = @[@0.01f, @1.1f, @1.0f]; bounceAnimation.keyTimes = @[@0.0f, @0.5f, @1.0f]; bounceAnimation.duration = 0.2; [self.popUpContainerView.layer addAnimation:bounceAnimation forKey:@"bounce"]; 

Essayez ces trois methods ..

**** vwTemp est ma vue d'alerte custome ****

 - (void)showAlertView { vwTemp.transform = CGAffineTransformMakeScale( 0.001, 0.001); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/1.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)]; vwTemp.transform = CGAffineTransformMakeScale( 1.1, 1.1); [UIView commitAnimations]; } 

  - (void)bounce1AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)]; vwTemp.transform = CGAffineTransformMakeScale (0.9, 0.9); [UIView commitAnimations]; } - (void)bounce2AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:kTransitionDuration/2]; [UIView setAnimationDelegate:self]; vwTemp.transform = CGAffineTransformIdentity; [UIView commitAnimations]; } 
  yourView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3/1.5]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce1AnimationStopped)]; [self.view addSubview:yourView]; yourView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1); [UIView commitAnimations]; 

Après avoir rebondi l'animation deux fois, ces deux methods sont utilisées.

 - (void)bounce1AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3/2]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(bounce2AnimationStopped)]; yourView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9); [UIView commitAnimations]; } - (void)bounce2AnimationStopped { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3/2]; yourView.transform = CGAffineTransformIdentity; [UIView commitAnimations]; } 

Utilisez le code ci-dessous dans swift3

 func popIn(yourView : UIView){ yourView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01) UIView.animateKeyframes(withDuration: 0.2, delay: 0.0, options: UIViewKeyframeAnimationOptions.calculationModeDiscrete, animations: { yourView.transform = .identity }, completion: nil) } func popOut(yourView: UIView) { yourView.transform = .identity UIView.animateKeyframes(withDuration: 0.2, delay: 0.0, options: UIViewKeyframeAnimationOptions.calculationModeDiscrete, animations: { yourView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01) }, completion:{(_ finish : Bool) in yourView.removeFromSuperview()} ) }