猎豆优选

TYAlertDropDownAnimation.m 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // TYAlertDropDownAnimation.m
  3. // TYAlertControllerDemo
  4. //
  5. // Created by tanyang on 15/10/27.
  6. // Copyright © 2015年 tanyang. All rights reserved.
  7. //
  8. #import "TYAlertDropDownAnimation.h"
  9. @implementation TYAlertDropDownAnimation
  10. - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
  11. {
  12. if (self.isPresenting) {
  13. return 0.5;
  14. }
  15. return 0.25;
  16. }
  17. - (void)presentAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
  18. {
  19. TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  20. alertController.backgroundView.alpha = 0.0;
  21. switch (alertController.preferredStyle) {
  22. case TYAlertControllerStyleAlert:
  23. alertController.alertView.transform = CGAffineTransformMakeTranslation(0, -CGRectGetMaxY(alertController.alertView.frame));
  24. break;
  25. case TYAlertControllerStyleActionSheet:
  26. NSLog(@"don't support ActionSheet style!");
  27. break;
  28. default:
  29. break;
  30. }
  31. UIView *containerView = [transitionContext containerView];
  32. [containerView addSubview:alertController.view];
  33. [UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.65 initialSpringVelocity:0.5 options:0 animations:^{
  34. alertController.backgroundView.alpha = 1.0;
  35. alertController.alertView.transform = CGAffineTransformIdentity;
  36. } completion:^(BOOL finished) {
  37. [transitionContext completeTransition:YES];
  38. }];
  39. }
  40. - (void)dismissAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
  41. {
  42. TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
  43. [UIView animateWithDuration:0.25 animations:^{
  44. alertController.backgroundView.alpha = 0.0;
  45. switch (alertController.preferredStyle) {
  46. case TYAlertControllerStyleAlert:
  47. alertController.alertView.alpha = 0.0;
  48. alertController.alertView.transform = CGAffineTransformMakeScale(0.9, 0.9);
  49. break;
  50. case TYAlertControllerStyleActionSheet:
  51. NSLog(@"don't support ActionSheet style!");
  52. break;
  53. default:
  54. break;
  55. }
  56. } completion:^(BOOL finished) {
  57. [transitionContext completeTransition:YES];
  58. }];
  59. }
  60. @end