UIView+XGAdd.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // UIView+XGAdd.m
  3. // XGAssetPickerController
  4. //
  5. // Created by huxinguang on 2018/11/8.
  6. // Copyright © 2018年 huxinguang. All rights reserved.
  7. //
  8. #import "UIView+XGAdd.h"
  9. @implementation UIView (XGAdd)
  10. - (CGFloat)left {
  11. return self.frame.origin.x;
  12. }
  13. - (void)setLeft:(CGFloat)x {
  14. CGRect frame = self.frame;
  15. frame.origin.x = x;
  16. self.frame = frame;
  17. }
  18. - (CGFloat)top {
  19. return self.frame.origin.y;
  20. }
  21. - (void)setTop:(CGFloat)y {
  22. CGRect frame = self.frame;
  23. frame.origin.y = y;
  24. self.frame = frame;
  25. }
  26. - (CGFloat)right {
  27. return self.frame.origin.x + self.frame.size.width;
  28. }
  29. - (void)setRight:(CGFloat)right {
  30. CGRect frame = self.frame;
  31. frame.origin.x = right - frame.size.width;
  32. self.frame = frame;
  33. }
  34. - (CGFloat)bottom {
  35. return self.frame.origin.y + self.frame.size.height;
  36. }
  37. - (void)setBottom:(CGFloat)bottom {
  38. CGRect frame = self.frame;
  39. frame.origin.y = bottom - frame.size.height;
  40. self.frame = frame;
  41. }
  42. - (CGFloat)width {
  43. return self.frame.size.width;
  44. }
  45. - (void)setWidth:(CGFloat)width {
  46. CGRect frame = self.frame;
  47. frame.size.width = width;
  48. self.frame = frame;
  49. }
  50. - (CGFloat)height {
  51. return self.frame.size.height;
  52. }
  53. - (void)setHeight:(CGFloat)height {
  54. CGRect frame = self.frame;
  55. frame.size.height = height;
  56. self.frame = frame;
  57. }
  58. - (CGFloat)centerX {
  59. return self.center.x;
  60. }
  61. - (void)setCenterX:(CGFloat)centerX {
  62. self.center = CGPointMake(centerX, self.center.y);
  63. }
  64. - (CGFloat)centerY {
  65. return self.center.y;
  66. }
  67. - (void)setCenterY:(CGFloat)centerY {
  68. self.center = CGPointMake(self.center.x, centerY);
  69. }
  70. - (CGPoint)origin {
  71. return self.frame.origin;
  72. }
  73. - (void)setOrigin:(CGPoint)origin {
  74. CGRect frame = self.frame;
  75. frame.origin = origin;
  76. self.frame = frame;
  77. }
  78. - (CGSize)size {
  79. return self.frame.size;
  80. }
  81. - (void)setSize:(CGSize)size {
  82. CGRect frame = self.frame;
  83. frame.size = size;
  84. self.frame = frame;
  85. }
  86. + (void)showScaleAnimationWithLayer:(CALayer *)layer type:(ScaleAnimationType)type{
  87. NSNumber *animationScale1 = type == ScaleAnimationToBigger ? @(1.15) : @(0.5);
  88. NSNumber *animationScale2 = type == ScaleAnimationToBigger ? @(0.92) : @(1.15);
  89. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  90. [layer setValue:animationScale1 forKeyPath:@"transform.scale"];
  91. } completion:^(BOOL finished) {
  92. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  93. [layer setValue:animationScale2 forKeyPath:@"transform.scale"];
  94. } completion:^(BOOL finished) {
  95. [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  96. [layer setValue:@(1.0) forKeyPath:@"transform.scale"];
  97. } completion:nil];
  98. }];
  99. }];
  100. }
  101. @end