UIView+Layout.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // UIView+Layout.m
  3. //
  4. // Created by 谭真 on 15/2/24.
  5. // Copyright © 2015年 谭真. All rights reserved.
  6. //
  7. #import "UIView+Layout.h"
  8. @implementation UIView (Layout)
  9. - (CGFloat)tz_left {
  10. return self.frame.origin.x;
  11. }
  12. - (void)setTz_left:(CGFloat)x {
  13. CGRect frame = self.frame;
  14. frame.origin.x = x;
  15. self.frame = frame;
  16. }
  17. - (CGFloat)tz_top {
  18. return self.frame.origin.y;
  19. }
  20. - (void)setTz_top:(CGFloat)y {
  21. CGRect frame = self.frame;
  22. frame.origin.y = y;
  23. self.frame = frame;
  24. }
  25. - (CGFloat)tz_right {
  26. return self.frame.origin.x + self.frame.size.width;
  27. }
  28. - (void)setTz_right:(CGFloat)right {
  29. CGRect frame = self.frame;
  30. frame.origin.x = right - frame.size.width;
  31. self.frame = frame;
  32. }
  33. - (CGFloat)tz_bottom {
  34. return self.frame.origin.y + self.frame.size.height;
  35. }
  36. - (void)setTz_bottom:(CGFloat)bottom {
  37. CGRect frame = self.frame;
  38. frame.origin.y = bottom - frame.size.height;
  39. self.frame = frame;
  40. }
  41. - (CGFloat)tz_width {
  42. return self.frame.size.width;
  43. }
  44. - (void)setTz_width:(CGFloat)width {
  45. CGRect frame = self.frame;
  46. frame.size.width = width;
  47. self.frame = frame;
  48. }
  49. - (CGFloat)tz_height {
  50. return self.frame.size.height;
  51. }
  52. - (void)setTz_height:(CGFloat)height {
  53. CGRect frame = self.frame;
  54. frame.size.height = height;
  55. self.frame = frame;
  56. }
  57. - (CGFloat)tz_centerX {
  58. return self.center.x;
  59. }
  60. - (void)setTz_centerX:(CGFloat)centerX {
  61. self.center = CGPointMake(centerX, self.center.y);
  62. }
  63. - (CGFloat)tz_centerY {
  64. return self.center.y;
  65. }
  66. - (void)setTz_centerY:(CGFloat)centerY {
  67. self.center = CGPointMake(self.center.x, centerY);
  68. }
  69. - (CGPoint)tz_origin {
  70. return self.frame.origin;
  71. }
  72. - (void)setTz_origin:(CGPoint)origin {
  73. CGRect frame = self.frame;
  74. frame.origin = origin;
  75. self.frame = frame;
  76. }
  77. - (CGSize)tz_size {
  78. return self.frame.size;
  79. }
  80. - (void)setTz_size:(CGSize)size {
  81. CGRect frame = self.frame;
  82. frame.size = size;
  83. self.frame = frame;
  84. }
  85. + (void)showOscillatoryAnimationWithLayer:(CALayer *)layer type:(TZOscillatoryAnimationType)type{
  86. NSNumber *animationScale1 = type == TZOscillatoryAnimationToBigger ? @(1.15) : @(0.5);
  87. NSNumber *animationScale2 = type == TZOscillatoryAnimationToBigger ? @(0.92) : @(1.15);
  88. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  89. [layer setValue:animationScale1 forKeyPath:@"transform.scale"];
  90. } completion:^(BOOL finished) {
  91. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  92. [layer setValue:animationScale2 forKeyPath:@"transform.scale"];
  93. } completion:^(BOOL finished) {
  94. [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut animations:^{
  95. [layer setValue:@(1.0) forKeyPath:@"transform.scale"];
  96. } completion:nil];
  97. }];
  98. }];
  99. }
  100. @end