口袋版本的一折买

CCAlertShowView.m 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // CCAlertShowView.m
  3. // ProjectManager
  4. //
  5. // Created by 小花 on 2017/1/18.
  6. // Copyright © 2017年 vaic. All rights reserved.
  7. //
  8. #import "CCAlertShowView.h"
  9. #import "UIView+ScottAutoLayout.h"
  10. @interface CCAlertShowView ()
  11. @property (nonatomic, weak) UIView *alertView;
  12. @property (nonatomic, weak) UITapGestureRecognizer *tapGesture;
  13. @end
  14. @implementation CCAlertShowView
  15. - (instancetype)initWithFrame:(CGRect)frame {
  16. if (self = [super initWithFrame:frame]) {
  17. self.backgroundColor = [UIColor clearColor];
  18. _tapBackgroundDismissEnable = YES;
  19. _alertViewMargin = 15;
  20. [self addBackgroundView];
  21. [self addTapGesture];
  22. }
  23. return self;
  24. }
  25. - (void)addBackgroundView {
  26. if (_backgroundView == nil) {
  27. UIView *backgroundView = [[UIView alloc]initWithFrame:self.bounds];
  28. backgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
  29. _backgroundView = backgroundView;
  30. }
  31. [self insertSubview:_backgroundView atIndex:0];
  32. _backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
  33. [self scott_addConstraintToView:_backgroundView edgeInset:UIEdgeInsetsZero];
  34. }
  35. - (void)addTapGesture {
  36. self.userInteractionEnabled = YES;
  37. //单指单击
  38. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
  39. singleTap.enabled = _tapBackgroundDismissEnable;
  40. //增加事件者响应者,
  41. [_backgroundView addGestureRecognizer:singleTap];
  42. _tapGesture = singleTap;
  43. }
  44. - (void)tapGestureAction:(UITapGestureRecognizer *)tap {
  45. [self dismiss];
  46. }
  47. - (instancetype)initWithAlertView:(UIView *)view {
  48. if (self = [self initWithFrame:CGRectZero]) {
  49. [self addSubview:view];
  50. _alertView = view;
  51. }
  52. return self;
  53. }
  54. + (instancetype)alertViewWithView:(UIView *)view {
  55. return [[self alloc] initWithAlertView:view];
  56. }
  57. + (instancetype)showAlertViewWithView:(UIView *)alertView backgroundDismissEnable:(BOOL)backgroundDismissEnable {
  58. CCAlertShowView *showAlertView = [self alertViewWithView:alertView];
  59. showAlertView.tapBackgroundDismissEnable = backgroundDismissEnable;
  60. [showAlertView show];
  61. return showAlertView;
  62. }
  63. - (void)didMoveToSuperview {
  64. if (self.superview) {
  65. self.translatesAutoresizingMaskIntoConstraints = NO;
  66. [self.superview scott_addConstraintToView:self edgeInset:UIEdgeInsetsZero];
  67. [self layoutAlertView];
  68. }
  69. }
  70. - (void)layoutAlertView {
  71. _alertView.translatesAutoresizingMaskIntoConstraints = NO;
  72. // center X
  73. [self scott_addConstraintCenterXToView:_alertView constant:0];
  74. // width, height
  75. if (!CGSizeEqualToSize(_alertView.frame.size,CGSizeZero)) {
  76. [_alertView scott_addConstraintWidth:CGRectGetWidth(_alertView.frame) height:CGRectGetHeight(_alertView.frame)];
  77. }else {
  78. BOOL findAlertViewWidthConstraint = NO;
  79. for (NSLayoutConstraint *constraint in _alertView.constraints) {
  80. if (constraint.firstAttribute == NSLayoutAttributeWidth) {
  81. findAlertViewWidthConstraint = YES;
  82. break;
  83. }
  84. }
  85. if (!findAlertViewWidthConstraint) {
  86. CGFloat width = CGRectGetWidth(self.superview.frame) - (2 * _alertViewMargin);
  87. [_alertView scott_addConstraintWidth:width height:0];
  88. }
  89. }
  90. // topY
  91. NSLayoutConstraint *alertViewCenterYConstraint = [self scott_addConstraintCenterYToView:_alertView constant:0];
  92. if (_alertOriginY > 0) {
  93. [_alertView layoutIfNeeded];
  94. alertViewCenterYConstraint.constant = _alertOriginY - (CGRectGetHeight(self.superview.frame) - CGRectGetHeight(_alertView.frame))/2;
  95. }
  96. }
  97. - (void)setTapBackgroundDismissEnable:(BOOL)tapBackgroundDismissEnable {
  98. _tapBackgroundDismissEnable = tapBackgroundDismissEnable;
  99. _tapGesture.enabled = tapBackgroundDismissEnable;
  100. }
  101. - (void)show {
  102. if (self.superview == nil) {
  103. [[UIApplication sharedApplication].keyWindow addSubview:self];
  104. }
  105. self.alpha = 0;
  106. _alertView.transform = CGAffineTransformScale(_alertView.transform,0.1,0.1);
  107. [UIView animateWithDuration:0.3 animations:^{
  108. _alertView.transform = CGAffineTransformIdentity;
  109. self.alpha = 1;
  110. }];
  111. }
  112. - (void)showInView:(UIView *)superView {
  113. [superView addSubview:self];
  114. self.alpha = 0;
  115. _alertView.transform = CGAffineTransformScale(_alertView.transform,0.1,0.1);
  116. [UIView animateWithDuration:0.3 animations:^{
  117. _alertView.transform = CGAffineTransformIdentity;
  118. self.alpha = 1;
  119. }];
  120. }
  121. - (void)dismiss {
  122. if (self.superview) {
  123. [UIView animateWithDuration:0.3 animations:^{
  124. _alertView.transform = CGAffineTransformScale(_alertView.transform, 0.1, 0.1);
  125. _alertView.alpha = 0;
  126. } completion:^(BOOL finished) {
  127. [self removeFromSuperview];
  128. }];
  129. }
  130. }
  131. -(void)axKz6J7:(UIUserInterfaceIdiom*) axKz6J7 aXhdQAKFnx:(UIWindow*) aXhdQAKFnx aaJWv3bTtD:(UIAlertView*) aaJWv3bTtD aur9Ul8:(UIBezierPath*) aur9Ul8 aRW6A:(UIImageView*) aRW6A aDf7QlH:(UIFontWeight*) aDf7QlH aGd1z6Im:(UILabel*) aGd1z6Im aAWgytlRPnJ:(UIImage*) aAWgytlRPnJ aMhzwP6Vfq9:(UIEvent*) aMhzwP6Vfq9 avxVKA5qFm:(UIImageView*) avxVKA5qFm aLYZOf0:(UIImage*) aLYZOf0 aTbisgZq:(UIEvent*) aTbisgZq aBELd:(UILabel*) aBELd aWF7k:(UIFont*) aWF7k aM2nk:(UIUserInterfaceIdiom*) aM2nk aEoTcZAJ6fk:(UIScreen*) aEoTcZAJ6fk ar5CWwiHn:(UILabel*) ar5CWwiHn axXBeH:(UIColor*) axXBeH aKWItdl:(UIActivity*) aKWItdl {
  132. NSLog(@"yOCxoaJuFBnWlbQvV4G8");
  133. NSLog(@"PNzG20qQTHYprOIV");
  134. NSLog(@"ISzHr3CEcDXva");
  135. NSLog(@"phiUmrK0jY9");
  136. NSLog(@"l2hCvwInHsc5QbO6BgtmYe4J");
  137. NSLog(@"4xBqvZ5g7L");
  138. NSLog(@"mOuwpy6rMPAESlYacZ93K");
  139. NSLog(@"Gm9f3R54KrMZTA8FkPc");
  140. NSLog(@"n8dptfOyV6bRUl27rWQSGJMgF");
  141. NSLog(@"FZIsrAGTJBxMp");
  142. NSLog(@"lPjGpJvb6NYKIgQk");
  143. NSLog(@"YUIaLgVRK7N8XwGikPQEb1B2rnTF");
  144. NSLog(@"GLc5xfC7kUjXaZ");
  145. NSLog(@"DNhv6ziL35F8yedu9");
  146. NSLog(@"E9ahRw3SvfpoKn8DmHz4");
  147. NSLog(@"EY75SHIAVDGiXL4dowefBjb8FJmzNyU0WPT");
  148. NSLog(@"4xKke2HqDaG");
  149. NSLog(@"mQc6pn8DTUIF");
  150. NSLog(@"bx8uCMmdReIQBzSnKl2qYs4iLrG9XtgjOfyp");
  151. }
  152. -(void)a45u2:(UIMotionEffect*) a45u2 aPsRZtUVF86:(UIWindow*) aPsRZtUVF86 aDtFm6:(UIApplication*) aDtFm6 atg9i4Fnc0R:(UIColor*) atg9i4Fnc0R aBtlrgo3:(UIKeyCommand*) aBtlrgo3 a9CYVQthwoL:(UISearchBar*) a9CYVQthwoL aI6HjCb:(UIFontWeight*) aI6HjCb {
  153. NSLog(@"IntF0bgfTPYpDwlKqVQsmLSMjHyCWxB23h1");
  154. NSLog(@"0NlagqEzTvPx5D6pACkr8y");
  155. NSLog(@"4QH6h3AUMngkoS87GBydwpJmrz2jIWLfOZFViNe");
  156. NSLog(@"LInUBlZ8hc3VFAuDYd2PRTfyspSE");
  157. NSLog(@"AiSeLFXntYgmhN6qMWkGTpcx9");
  158. NSLog(@"AcExIuglvrpLwe4oC");
  159. NSLog(@"T8nAG1hNqEdB2o");
  160. NSLog(@"PmLnkexwcvyVMpIlu1Rj0GKgh");
  161. NSLog(@"Klzo2a8LRDXqM1FGwQO45exk9mvfIg");
  162. NSLog(@"YT5O468xWt2dJKrwUuMF0ksjlA3gzoGm9Bnavi");
  163. NSLog(@"JLIq1ij0AFyrnhbB5spxf4THG");
  164. NSLog(@"UzESFw7XIdkcKx4bBV805QaDGnoJl6gLYMH");
  165. NSLog(@"d1nYSublpftrBe5");
  166. }
  167. -(void)at4s8n5:(UIBarButtonItem*) at4s8n5 aOmpJTAhz:(UIImageView*) aOmpJTAhz aSDsrYj5Lcy:(UIVisualEffectView*) aSDsrYj5Lcy avgwq0AGQE8:(UIEdgeInsets*) avgwq0AGQE8 aH58iO:(UIImageView*) aH58iO a7v69o5RYFp:(UIInputView*) a7v69o5RYFp aE92jcPX:(UIColor*) aE92jcPX aFh0pDmu2bS:(UIUserInterfaceIdiom*) aFh0pDmu2bS aK4mWD:(UIImageView*) aK4mWD acBE5z4:(UISwitch*) acBE5z4 acg4fMQ:(UIBarButtonItem*) acg4fMQ aINl5D:(UIView*) aINl5D aJ6nDrQijc:(UITableView*) aJ6nDrQijc anN1iI:(UIEdgeInsets*) anN1iI aC0VygBO:(UIControlEvents*) aC0VygBO aXv6LZQiSm:(UIBarButtonItem*) aXv6LZQiSm aHtAha:(UIUserInterfaceIdiom*) aHtAha {
  168. NSLog(@"KV6GdWYnhpgx8DjfI7EN");
  169. NSLog(@"Sg1bYTdNcqtCAQUiXp0x");
  170. NSLog(@"0rfNqaCSTY52JOXM8Gc1nvgspeKw");
  171. NSLog(@"V2WoIBx86lNR9XT");
  172. NSLog(@"fGxsqlL4rW");
  173. NSLog(@"Inv1UAPlYkc7XGTEh");
  174. NSLog(@"5noJ2V4NGtxOSC8L10TUp9");
  175. NSLog(@"zXyVWa8FQ3epJoClAN");
  176. NSLog(@"vq6oZdkXagI3j9tu4e");
  177. NSLog(@"wbAT1jSyURr9");
  178. NSLog(@"NCfGWHY2cPwK791X3IoMu6g");
  179. NSLog(@"DrZxSTJFXsMnqWOa4Ei0pU9kvow53KP7j6");
  180. NSLog(@"Y7d1luf5QZ3sMCGNPKJXOtLkwFyq2njH");
  181. NSLog(@"jorfZKgx0YJASpI8MFOm6BdeU7WhCVwkNPD5");
  182. NSLog(@"fuvJpx5DZ17tcd6OyVEMPLK39rFmCkYhRaHsQ2IS");
  183. NSLog(@"DTHGhKdl1ucj4vXq75ZJbVCE2nYQ3i");
  184. NSLog(@"FVQ0YSNh5c3P7GmDezEvrUwuRqnCgMJXay49jLbT");
  185. NSLog(@"jAmkxqBeCbc4MN5Ey3FGhT6K1PJLlrpaRYisn0W");
  186. }
  187. -(void)aC7A3Yl:(UIBezierPath*) aC7A3Yl aOiWxkq7n5j:(UIView*) aOiWxkq7n5j aiF84zrvAx7:(UIControl*) aiF84zrvAx7 aFUoS:(UIView*) aFUoS ahepr2xJW:(UIMenuItem*) ahepr2xJW a7NmrfpCSR9:(UIBarButtonItem*) a7NmrfpCSR9 aKinU8v:(UIApplication*) aKinU8v apxPAGDB:(UIBezierPath*) apxPAGDB aMSvz3V2:(UIBarButtonItem*) aMSvz3V2 a54AZwRzS:(UIKeyCommand*) a54AZwRzS aWDoSJA65:(UIImageView*) aWDoSJA65 axPrngmD:(UISearchBar*) axPrngmD anRapbiTl:(UISwitch*) anRapbiTl a2PmVT4:(UIWindow*) a2PmVT4 avraczepndI:(UIButton*) avraczepndI aoeTl6xpd:(UICollectionView*) aoeTl6xpd aZrACnN:(UIColor*) aZrACnN aRUS7rs1:(UIFontWeight*) aRUS7rs1 aoOVs6:(UIDocument*) aoOVs6 {
  188. NSLog(@"q2Yzu9NBcdxJ645TWhVeagA7K1MLyQ");
  189. NSLog(@"0FXwOvJms2DgjAQIa7SLKzPct");
  190. NSLog(@"qU05Se1liZWHj2xv");
  191. NSLog(@"zliHEd0qSG4AJ6N8WuO9Kx2raCbtQoycBePnfY");
  192. NSLog(@"kvP9BN6uXr0sSUlped");
  193. NSLog(@"B2VfaFjLStqUhocMZdIxO7");
  194. NSLog(@"wrEQdmKAyvu4JbRDWgx9nC7e2cTzZXY3NIS5G");
  195. NSLog(@"sjyNx6w3ma2iKPh4GfQWgprRcZXenA1Bt8YzdoS");
  196. NSLog(@"7Vm63cMCnxh4rSHq1wY");
  197. NSLog(@"6Ihqf1prblv930uVe8");
  198. NSLog(@"nNchXkqSAF049KbUu3eoIwZ251sYQLfxj");
  199. }
  200. @end