省钱达人

TYAlertScaleFadeAnimation.m 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // TYAlertScaleFadeAnimation.m
  3. // TYAlertControllerDemo
  4. //
  5. // Created by SunYong on 15/9/2.
  6. // Copyright (c) 2015年 tanyang. All rights reserved.
  7. //
  8. #import "TYAlertScaleFadeAnimation.h"
  9. @implementation TYAlertScaleFadeAnimation
  10. - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
  11. {
  12. return 0.3;
  13. }
  14. - (void)presentAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
  15. {
  16. TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  17. alertController.backgroundView.alpha = 0.0;
  18. switch (alertController.preferredStyle) {
  19. case TYAlertControllerStyleAlert:
  20. alertController.alertView.alpha = 0.0;
  21. alertController.alertView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  22. break;
  23. case TYAlertControllerStyleActionSheet:
  24. alertController.alertView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(alertController.alertView.frame));
  25. break;
  26. default:
  27. break;
  28. }
  29. UIView *containerView = [transitionContext containerView];
  30. [containerView addSubview:alertController.view];
  31. [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
  32. alertController.backgroundView.alpha = 1.0;
  33. switch (alertController.preferredStyle) {
  34. case TYAlertControllerStyleAlert:
  35. alertController.alertView.alpha = 1.0;
  36. alertController.alertView.transform = CGAffineTransformIdentity;
  37. break;
  38. case TYAlertControllerStyleActionSheet:
  39. alertController.alertView.transform = CGAffineTransformIdentity;
  40. break;
  41. default:
  42. break;
  43. }
  44. } completion:^(BOOL finished) {
  45. [transitionContext completeTransition:YES];
  46. }];
  47. }
  48. - (void)dismissAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
  49. {
  50. TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
  51. [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
  52. alertController.backgroundView.alpha = 0.0;
  53. switch (alertController.preferredStyle) {
  54. case TYAlertControllerStyleAlert:
  55. alertController.alertView.alpha = 0.0;
  56. alertController.alertView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  57. break;
  58. case TYAlertControllerStyleActionSheet:
  59. alertController.alertView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(alertController.alertView.frame));
  60. break;
  61. default:
  62. break;
  63. }
  64. } completion:^(BOOL finished) {
  65. [transitionContext completeTransition:YES];
  66. }];
  67. }
  68. @end