口袋版本的一折买

TYAlertFadeAnimation.m 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // TYAlertDefaultAnimation.m
  3. // TYAlertControllerDemo
  4. //
  5. // Created by SunYong on 15/9/1.
  6. // Copyright (c) 2015年 tanyang. All rights reserved.
  7. //
  8. #import "TYAlertFadeAnimation.h"
  9. @implementation TYAlertFadeAnimation
  10. - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
  11. {
  12. if (self.isPresenting) {
  13. return 0.45;
  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.alpha = 0.0;
  24. alertController.alertView.transform = CGAffineTransformMakeScale(0.5, 0.5);
  25. break;
  26. case TYAlertControllerStyleActionSheet:
  27. alertController.alertView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(alertController.alertView.frame));
  28. break;
  29. default:
  30. break;
  31. }
  32. UIView *containerView = [transitionContext containerView];
  33. [containerView addSubview:alertController.view];
  34. [UIView animateWithDuration:0.25 animations:^{
  35. alertController.backgroundView.alpha = 1.0;
  36. switch (alertController.preferredStyle) {
  37. case TYAlertControllerStyleAlert:
  38. alertController.alertView.alpha = 1.0;
  39. alertController.alertView.transform = CGAffineTransformMakeScale(1.05, 1.05);
  40. break;
  41. case TYAlertControllerStyleActionSheet:
  42. alertController.alertView.transform = CGAffineTransformMakeTranslation(0, -10.0);
  43. break;
  44. default:
  45. break;
  46. }
  47. } completion:^(BOOL finished) {
  48. [UIView animateWithDuration:0.2 animations:^{
  49. alertController.alertView.transform = CGAffineTransformIdentity;
  50. } completion:^(BOOL finished) {
  51. [transitionContext completeTransition:YES];
  52. }];
  53. }];
  54. }
  55. - (void)dismissAnimateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
  56. {
  57. TYAlertController *alertController = (TYAlertController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
  58. [UIView animateWithDuration:0.25 animations:^{
  59. alertController.backgroundView.alpha = 0.0;
  60. switch (alertController.preferredStyle) {
  61. case TYAlertControllerStyleAlert:
  62. alertController.alertView.alpha = 0.0;
  63. alertController.alertView.transform = CGAffineTransformMakeScale(0.9, 0.9);
  64. break;
  65. case TYAlertControllerStyleActionSheet:
  66. alertController.alertView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(alertController.alertView.frame));
  67. break;
  68. default:
  69. break;
  70. }
  71. } completion:^(BOOL finished) {
  72. [transitionContext completeTransition:YES];
  73. }];
  74. }
  75. @end