UIView+TUIUtil.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // UIView+TUIUtil.m
  3. // TUICore
  4. //
  5. // Created by gg on 2021/10/9.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "UIView+TUIUtil.h"
  9. @implementation UIView (TUIUtil)
  10. - (void)roundedRect:(UIRectCorner)corner withCornerRatio:(CGFloat)cornerRatio {
  11. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(cornerRatio, cornerRatio)];
  12. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  13. maskLayer.frame = self.bounds;
  14. maskLayer.path = maskPath.CGPath;
  15. self.layer.mask = maskLayer;
  16. }
  17. + (void)showOscillatoryAnimationWithLayer:(CALayer *)layer type:(TUIOscillatoryAnimationType)type{
  18. NSNumber *animationScale1 = type == TUIOscillatoryAnimationToBigger ? @(1.15) : @(0.5);
  19. NSNumber *animationScale2 = type == TUIOscillatoryAnimationToBigger ? @(0.92) : @(1.15);
  20. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  21. [layer setValue:animationScale1 forKeyPath:@"transform.scale"];
  22. } completion:^(BOOL finished) {
  23. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  24. [layer setValue:animationScale2 forKeyPath:@"transform.scale"];
  25. } completion:^(BOOL finished) {
  26. [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  27. [layer setValue:@(1.0) forKeyPath:@"transform.scale"];
  28. } completion:nil];
  29. }];
  30. }];
  31. }
  32. @end