Animations.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2014-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "Animations.h"
  21. #import "RectUtil.h"
  22. @implementation Animations
  23. + (void) bounceToRect:(CGRect)toFrame view: (UIView *) view endAction: (void (^)(void)) action
  24. {
  25. CGRect finalRect = view.frame;
  26. [view.superview bringSubviewToFront: view];
  27. UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseInOut;
  28. [UIView animateWithDuration:0.5 delay:0.0 options: options animations:^{
  29. view.frame = toFrame;
  30. view.hidden = NO;
  31. } completion:^(BOOL finished){
  32. [UIView animateWithDuration:0.9 delay:0.1 options: options animations:^{
  33. view.frame = finalRect;
  34. } completion:^(BOOL finished){
  35. if (action) {
  36. action();
  37. }
  38. }];
  39. }];
  40. }
  41. + (void) slideFromLeftBounce: (UIView *) view endAction: (void (^)(void)) action
  42. {
  43. CGRect finalRect = view.frame;
  44. CGRect startRect = [RectUtil setXPositionOf:view.frame x: - (view.frame.origin.x + view.frame.size.width)];
  45. CGRect intermediateRect = [RectUtil setXPositionOf:view.frame x:view.frame.origin.x + 10];
  46. view.frame = startRect;
  47. view.hidden = NO;
  48. [view.superview bringSubviewToFront: view];
  49. UIViewAnimationOptions options = 0;
  50. [UIView animateWithDuration:0.5 delay:0.0 options: options animations:^{
  51. view.frame = intermediateRect;
  52. view.hidden = NO;
  53. } completion:^(BOOL finished){
  54. [UIView animateWithDuration:0.25 delay:0.0 options: options animations:^{
  55. view.frame = finalRect;
  56. } completion:^(BOOL finished){
  57. if (action) {
  58. action();
  59. }
  60. }];
  61. }];
  62. }
  63. + (void) scaleBounceView: (UIView *) view max: (CGFloat) max min: (CGFloat) min endAction: (void (^)(void)) action
  64. {
  65. CGAffineTransform scaleBig = CGAffineTransformScale(CGAffineTransformIdentity, max, max);
  66. CGAffineTransform scaleSmall = CGAffineTransformScale(CGAffineTransformIdentity, min, min);
  67. [view.superview bringSubviewToFront: view];
  68. UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState;
  69. [UIView animateWithDuration:0.2 delay:0.0 options: options animations:^{
  70. view.transform = scaleBig;
  71. } completion:^(BOOL finished){
  72. [UIView animateWithDuration:0.1 delay:0.0 options: options animations:^{
  73. view.transform = scaleSmall;
  74. } completion:^(BOOL finished){
  75. view.transform = CGAffineTransformIdentity;
  76. if (action) {
  77. action();
  78. }
  79. }];
  80. }];
  81. }
  82. @end