PNSBuildModelUtils.m 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. //
  2. // PNSBuildModelUtils.m
  3. // ATAuthSceneDemo
  4. //
  5. // Created by 刘超的MacBook on 2020/8/6.
  6. // Copyright © 2020 刘超的MacBook. All rights reserved.
  7. //
  8. #import "PNSBuildModelUtils.h"
  9. @implementation PNSBuildModelUtils
  10. + (TXCustomModel *)buildModelWithStyle:(PNSBuildModelStyle)style
  11. button1Title:(NSString *)button1Title
  12. target1:(id)target1
  13. selector1:(SEL)selector1
  14. button2Title:(NSString *)button2Title
  15. target2:(id)target2
  16. selector2:(SEL)selector2 {
  17. TXCustomModel *model = nil;
  18. switch (style) {
  19. case PNSBuildModelStylePortrait:
  20. model = [self buildFullScreenPortraitModelWithButton1Title:button1Title
  21. target1:target1
  22. selector1:selector1
  23. button2Title:button2Title
  24. target2:target2
  25. selector2:selector2];
  26. break;
  27. case PNSBuildModelStyleLandscape:
  28. model = [self buildFullScreenLandscapeModelWithButton1Title:button1Title
  29. target1:target1
  30. selector1:selector1
  31. button2Title:button2Title
  32. target2:target2
  33. selector2:selector2];
  34. break;
  35. case PNSBuildModelStyleAutorotate:
  36. model = [self buildFullScreenAutorotateModelWithButton1Title:button1Title
  37. target1:target1
  38. selector1:selector1
  39. button2Title:button2Title
  40. target2:target2
  41. selector2:selector2];
  42. break;
  43. case PNSBuildModelStyleAlertPortrait:
  44. model = [self buildAlertPortraitModeWithButton1Title:button1Title
  45. target1:target1
  46. selector1:selector1
  47. button2Title:button2Title
  48. target2:target2
  49. selector2:selector2];
  50. break;
  51. case PNSBuildModelStyleAlertLandscape:
  52. model = [self buildAlertLandscapeModeWithButton1Title:button1Title
  53. target1:target1
  54. selector1:selector1
  55. button2Title:button2Title
  56. target2:target2
  57. selector2:selector2];
  58. break;
  59. case PNSBuildModelStyleAlertAutorotate:
  60. model = [self buildAlertAutorotateModeWithButton1Title:button1Title
  61. target1:target1
  62. selector1:selector1
  63. button2Title:button2Title
  64. target2:target2
  65. selector2:selector2];
  66. break;
  67. case PNSBuildModelStyleSheetPortrait:
  68. model = [self buildSheetPortraitModelWithButton1Title:button1Title
  69. target1:target1
  70. selector1:selector1
  71. button2Title:button2Title
  72. target2:target2
  73. selector2:selector2];
  74. break;
  75. case PNSDIYAlertPortraitFade:
  76. model = [self buildAlertFadeModelWithButton1Title:button1Title
  77. target1:target1
  78. selector1:selector1
  79. button2Title:button2Title
  80. target2:target2
  81. selector2:selector2];
  82. break;
  83. case PNSDIYAlertPortraitBounce:
  84. model = [self buildAlertBounceModelWithButton1Title:button1Title
  85. target1:target1
  86. selector1:selector1
  87. button2Title:button2Title
  88. target2:target2
  89. selector2:selector2];
  90. break;
  91. case PNSDIYAlertPortraitDropDown:
  92. model = [self buildAlertDropDownModelWithButton1Title:button1Title
  93. target1:target1
  94. selector1:selector1
  95. button2Title:button2Title
  96. target2:target2
  97. selector2:selector2];
  98. break;
  99. case PNSDIYPortraitFade:
  100. model = [self buildFadeModelWithButton1Title:button1Title
  101. target1:target1
  102. selector1:selector1
  103. button2Title:button2Title
  104. target2:target2
  105. selector2:selector2];
  106. break;
  107. case PNSDIYPortraitScale:
  108. model = [self buildScaleModelWithButton1Title:button1Title
  109. target1:target1
  110. selector1:selector1
  111. button2Title:button2Title
  112. target2:target2
  113. selector2:selector2];
  114. break;
  115. default:
  116. break;
  117. }
  118. return model;
  119. }
  120. #pragma mark - 全屏相关
  121. + (TXCustomModel *)buildFullScreenPortraitModelWithButton1Title:(NSString *)button1Title
  122. target1:(id)target1
  123. selector1:(SEL)selector1
  124. button2Title:(NSString *)button2Title
  125. target2:(id)target2
  126. selector2:(SEL)selector2 {
  127. TXCustomModel *model = [[TXCustomModel alloc] init];
  128. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
  129. model.navColor = [UIColor orangeColor];
  130. NSDictionary *attributes = @{
  131. NSForegroundColorAttributeName : [UIColor whiteColor],
  132. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  133. };
  134. model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  135. model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
  136. model.logoImage = [UIImage imageNamed:@"taobao"];
  137. model.changeBtnIsHidden = YES;
  138. model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
  139. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  140. [button1 setTitle:button1Title forState:UIControlStateNormal];
  141. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  142. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  143. [button2 setTitle:button2Title forState:UIControlStateNormal];
  144. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  145. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  146. [superCustomView addSubview:button1];
  147. [superCustomView addSubview:button2];
  148. };
  149. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  150. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  151. CGRectGetMaxY(loginFrame) + 20,
  152. CGRectGetWidth(loginFrame),
  153. 30);
  154. button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
  155. CGRectGetMaxY(button1.frame) + 15,
  156. CGRectGetWidth(loginFrame),
  157. 30);
  158. };
  159. return model;
  160. }
  161. + (TXCustomModel *)buildFullScreenLandscapeModelWithButton1Title:(NSString *)button1Title
  162. target1:(id)target1
  163. selector1:(SEL)selector1
  164. button2Title:(NSString *)button2Title
  165. target2:(id)target2
  166. selector2:(SEL)selector2 {
  167. TXCustomModel *model = [[TXCustomModel alloc] init];
  168. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscape;
  169. model.navColor = [UIColor orangeColor];
  170. NSDictionary *attributes = @{
  171. NSForegroundColorAttributeName : [UIColor whiteColor],
  172. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  173. };
  174. model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  175. model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
  176. model.logoImage = [UIImage imageNamed:@"taobao"];
  177. model.sloganIsHidden = YES;
  178. model.changeBtnIsHidden = YES;
  179. model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
  180. model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  181. frame.size.width = 80;
  182. frame.size.height = 80;
  183. frame.origin.y = 15;
  184. frame.origin.x = (superViewSize.width - 80) * 0.5;
  185. return frame;
  186. };
  187. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  188. frame.origin.y = 15 + 80 + 15;
  189. return frame;
  190. };
  191. model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  192. frame.origin.y = 110 + 30 + 20;
  193. return frame;
  194. };
  195. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  196. [button1 setTitle:button1Title forState:UIControlStateNormal];
  197. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  198. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  199. [button2 setTitle:button2Title forState:UIControlStateNormal];
  200. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  201. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  202. [superCustomView addSubview:button1];
  203. [superCustomView addSubview:button2];
  204. };
  205. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  206. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  207. CGRectGetMaxY(loginFrame) + 20,
  208. CGRectGetWidth(loginFrame) * 0.5,
  209. 30);
  210. button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
  211. CGRectGetMinY(button1.frame),
  212. CGRectGetWidth(loginFrame) * 0.5,
  213. 30);
  214. };
  215. return model;
  216. }
  217. + (TXCustomModel *)buildFullScreenAutorotateModelWithButton1Title:(NSString *)button1Title
  218. target1:(id)target1
  219. selector1:(SEL)selector1
  220. button2Title:(NSString *)button2Title
  221. target2:(id)target2
  222. selector2:(SEL)selector2 {
  223. TXCustomModel *model = [[TXCustomModel alloc] init];
  224. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskAllButUpsideDown;
  225. model.navColor = [UIColor orangeColor];
  226. NSDictionary *attributes = @{
  227. NSForegroundColorAttributeName : [UIColor whiteColor],
  228. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  229. };
  230. model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  231. model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
  232. model.logoImage = [UIImage imageNamed:@"taobao"];
  233. model.changeBtnIsHidden = YES;
  234. model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
  235. model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  236. frame.size.width = 80;
  237. frame.size.height = 80;
  238. frame.origin.y = screenSize.height > screenSize.width ? 30 : 15;
  239. frame.origin.x = (superViewSize.width - 80) * 0.5;
  240. return frame;
  241. };
  242. model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  243. if (screenSize.height > screenSize.width) {
  244. frame.size.width = superViewSize.width - 40;
  245. frame.size.height = 20;
  246. frame.origin.x = 20;
  247. frame.origin.y = 20 + 80 + 20;
  248. return frame;
  249. } else {
  250. return CGRectZero;
  251. }
  252. };
  253. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  254. if (screenSize.height > screenSize.width) {
  255. frame.origin.y = 130 + 20 + 15;
  256. } else {
  257. frame.origin.y = 15 + 80 + 15;
  258. }
  259. return frame;
  260. };
  261. model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  262. if (screenSize.height > screenSize.width) {
  263. frame.origin.y = 170 + 30 + 20;
  264. } else {
  265. frame.origin.y = 110 + 30 + 20;
  266. }
  267. return frame;
  268. };
  269. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  270. [button1 setTitle:button1Title forState:UIControlStateNormal];
  271. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  272. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  273. [button2 setTitle:button2Title forState:UIControlStateNormal];
  274. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  275. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  276. [superCustomView addSubview:button1];
  277. [superCustomView addSubview:button2];
  278. };
  279. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  280. if (screenSize.height > screenSize.width) {
  281. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  282. CGRectGetMaxY(loginFrame) + 20,
  283. CGRectGetWidth(loginFrame),
  284. 30);
  285. button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
  286. CGRectGetMaxY(button1.frame) + 15,
  287. CGRectGetWidth(loginFrame),
  288. 30);
  289. } else {
  290. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  291. CGRectGetMaxY(loginFrame) + 20,
  292. CGRectGetWidth(loginFrame) * 0.5,
  293. 30);
  294. button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
  295. CGRectGetMinY(button1.frame),
  296. CGRectGetWidth(loginFrame) * 0.5,
  297. 30);
  298. }
  299. };
  300. return model;
  301. }
  302. #pragma mark - 弹窗
  303. + (TXCustomModel *)buildAlertPortraitModeWithButton1Title:(NSString *)button1Title
  304. target1:(id)target1
  305. selector1:(SEL)selector1
  306. button2Title:(NSString *)button2Title
  307. target2:(id)target2
  308. selector2:(SEL)selector2 {
  309. TXCustomModel *model = [[TXCustomModel alloc] init];
  310. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
  311. model.alertCornerRadiusArray = @[@10, @10, @10, @10];
  312. model.alertTitleBarColor = [UIColor orangeColor];
  313. NSDictionary *attributes = @{
  314. NSForegroundColorAttributeName : [UIColor whiteColor],
  315. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  316. };
  317. model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  318. model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
  319. model.logoImage = [UIImage imageNamed:@"taobao"];
  320. model.changeBtnIsHidden = YES;
  321. model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
  322. model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  323. frame.size.width = superViewSize.width * 0.8;
  324. frame.size.height = frame.size.width / 0.618;
  325. frame.origin.x = (superViewSize.width - frame.size.width) * 0.5;
  326. frame.origin.y = (superViewSize.height - frame.size.height) * 0.5;
  327. return frame;
  328. };
  329. model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  330. frame.size.width = 80;
  331. frame.size.height = 80;
  332. frame.origin.y = 20;
  333. frame.origin.x = (superViewSize.width - 80) * 0.5;
  334. return frame;
  335. };
  336. model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  337. frame.origin.y = 20 + 80 + 20;
  338. return frame;
  339. };
  340. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  341. frame.origin.y = 120 + 20 + 15;
  342. return frame;
  343. };
  344. model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  345. frame.origin.y = 155 + 20 + 30;
  346. return frame;
  347. };
  348. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  349. [button1 setTitle:button1Title forState:UIControlStateNormal];
  350. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  351. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  352. [button2 setTitle:button2Title forState:UIControlStateNormal];
  353. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  354. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  355. [superCustomView addSubview:button1];
  356. [superCustomView addSubview:button2];
  357. };
  358. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  359. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  360. CGRectGetMaxY(loginFrame) + 20,
  361. CGRectGetWidth(loginFrame),
  362. 30);
  363. button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
  364. CGRectGetMaxY(button1.frame) + 15,
  365. CGRectGetWidth(loginFrame),
  366. 30);
  367. };
  368. return model;
  369. }
  370. + (TXCustomModel *)buildAlertLandscapeModeWithButton1Title:(NSString *)button1Title
  371. target1:(id)target1
  372. selector1:(SEL)selector1
  373. button2Title:(NSString *)button2Title
  374. target2:(id)target2
  375. selector2:(SEL)selector2 {
  376. TXCustomModel *model = [[TXCustomModel alloc] init];
  377. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscape;
  378. model.alertCornerRadiusArray = @[@10, @10, @10, @10];
  379. model.alertTitleBarColor = [UIColor orangeColor];
  380. NSDictionary *attributes = @{
  381. NSForegroundColorAttributeName : [UIColor whiteColor],
  382. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  383. };
  384. model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  385. model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
  386. model.logoIsHidden = YES;
  387. model.sloganIsHidden = YES;
  388. model.changeBtnIsHidden = YES;
  389. model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
  390. model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  391. frame.size.height = superViewSize.height * 0.8;
  392. frame.size.width = frame.size.height / 0.618;
  393. frame.origin.x = (superViewSize.width - frame.size.width) * 0.5;
  394. frame.origin.y = (superViewSize.height - frame.size.height) * 0.5;
  395. return frame;
  396. };
  397. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  398. frame.origin.y = 30;
  399. return frame;
  400. };
  401. model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  402. frame.origin.y = 30 + 20 + 30;
  403. return frame;
  404. };
  405. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  406. [button1 setTitle:button1Title forState:UIControlStateNormal];
  407. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  408. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  409. [button2 setTitle:button2Title forState:UIControlStateNormal];
  410. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  411. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  412. [superCustomView addSubview:button1];
  413. [superCustomView addSubview:button2];
  414. };
  415. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  416. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  417. CGRectGetMaxY(loginFrame) + 20,
  418. CGRectGetWidth(loginFrame) * 0.5,
  419. 30);
  420. button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
  421. CGRectGetMinY(button1.frame),
  422. CGRectGetWidth(loginFrame) * 0.5,
  423. 30);
  424. };
  425. return model;
  426. }
  427. + (TXCustomModel *)buildAlertAutorotateModeWithButton1Title:(NSString *)button1Title
  428. target1:(id)target1
  429. selector1:(SEL)selector1
  430. button2Title:(NSString *)button2Title
  431. target2:(id)target2
  432. selector2:(SEL)selector2 {
  433. TXCustomModel *model = [[TXCustomModel alloc] init];
  434. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskAllButUpsideDown;
  435. model.alertCornerRadiusArray = @[@10, @10, @10, @10];
  436. model.alertTitleBarColor = [UIColor orangeColor];
  437. NSDictionary *attributes = @{
  438. NSForegroundColorAttributeName : [UIColor whiteColor],
  439. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  440. };
  441. model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  442. model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
  443. model.logoImage = [UIImage imageNamed:@"taobao"];
  444. model.sloganIsHidden = YES;
  445. model.changeBtnIsHidden = YES;
  446. model.privacyOne = @[@"自定义协议", @"https://www.taobao.com"];
  447. model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  448. if (screenSize.height > screenSize.width) {
  449. frame.size.width = superViewSize.width * 0.8;
  450. frame.size.height = frame.size.width / 0.618;
  451. } else {
  452. frame.size.height = superViewSize.height * 0.8;
  453. frame.size.width = frame.size.height / 0.618;
  454. }
  455. frame.origin.x = (superViewSize.width - frame.size.width) * 0.5;
  456. frame.origin.y = (superViewSize.height - frame.size.height) * 0.5;
  457. return frame;
  458. };
  459. model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  460. if (screenSize.height > screenSize.width) {
  461. frame.size.width = 80;
  462. frame.size.height = 80;
  463. frame.origin.y = 20;
  464. frame.origin.x = (superViewSize.width - 80) * 0.5;
  465. } else {
  466. frame = CGRectZero;
  467. }
  468. return frame;
  469. };
  470. model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  471. if (screenSize.height > screenSize.width) {
  472. frame.size.height = 20;
  473. frame.size.width = superViewSize.width - 40;
  474. frame.origin.x = 20;
  475. frame.origin.y = 20 + 80 + 20;
  476. } else {
  477. frame = CGRectZero;
  478. }
  479. return frame;
  480. };
  481. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  482. if (screenSize.height > screenSize.width) {
  483. frame.origin.y = 120 + 20 + 15;
  484. } else {
  485. frame.origin.y = 30;
  486. }
  487. return frame;
  488. };
  489. model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  490. if (screenSize.height > screenSize.width) {
  491. frame.origin.y = 155 + 20 + 30;
  492. } else {
  493. frame.origin.y = 30 + 20 + 30;
  494. }
  495. return frame;
  496. };
  497. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  498. [button1 setTitle:button1Title forState:UIControlStateNormal];
  499. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  500. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  501. [button2 setTitle:button2Title forState:UIControlStateNormal];
  502. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  503. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  504. [superCustomView addSubview:button1];
  505. [superCustomView addSubview:button2];
  506. };
  507. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  508. if (screenSize.height > screenSize.width) {
  509. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  510. CGRectGetMaxY(loginFrame) + 20,
  511. CGRectGetWidth(loginFrame),
  512. 30);
  513. button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
  514. CGRectGetMaxY(button1.frame) + 15,
  515. CGRectGetWidth(loginFrame),
  516. 30);
  517. } else {
  518. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  519. CGRectGetMaxY(loginFrame) + 20,
  520. CGRectGetWidth(loginFrame) * 0.5,
  521. 30);
  522. button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
  523. CGRectGetMinY(button1.frame),
  524. CGRectGetWidth(loginFrame) * 0.5,
  525. 30);
  526. }
  527. };
  528. return model;
  529. }
  530. #pragma mark - 底部弹窗
  531. + (TXCustomModel *)buildSheetPortraitModelWithButton1Title:(NSString *)button1Title
  532. target1:(id)target1
  533. selector1:(SEL)selector1
  534. button2Title:(NSString *)button2Title
  535. target2:(id)target2
  536. selector2:(SEL)selector2 {
  537. TXCustomModel *model = [[TXCustomModel alloc] init];
  538. model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
  539. model.alertCornerRadiusArray = @[@10, @0, @0, @10];
  540. model.alertTitleBarColor = [UIColor orangeColor];
  541. NSDictionary *attributes = @{
  542. NSForegroundColorAttributeName : [UIColor whiteColor],
  543. NSFontAttributeName : [UIFont systemFontOfSize:20.0]
  544. };
  545. model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
  546. model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
  547. model.logoImage = [UIImage imageNamed:@"taobao"];
  548. model.changeBtnIsHidden = YES;
  549. model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
  550. model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  551. frame.size.width = superViewSize.width;
  552. frame.size.height = 460;
  553. frame.origin.x = 0;
  554. frame.origin.y = superViewSize.height - frame.size.height;
  555. return frame;
  556. };
  557. model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  558. frame.size.width = 80;
  559. frame.size.height = 80;
  560. frame.origin.y = 20;
  561. frame.origin.x = (superViewSize.width - 80) * 0.5;
  562. return frame;
  563. };
  564. model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  565. frame.origin.y = 20 + 80 + 20;
  566. return frame;
  567. };
  568. model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  569. frame.origin.y = 120 + 20 + 15;
  570. return frame;
  571. };
  572. model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  573. frame.origin.y = 155 + 20 + 30;
  574. return frame;
  575. };
  576. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
  577. [button1 setTitle:button1Title forState:UIControlStateNormal];
  578. [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
  579. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
  580. [button2 setTitle:button2Title forState:UIControlStateNormal];
  581. [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
  582. model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
  583. [superCustomView addSubview:button1];
  584. [superCustomView addSubview:button2];
  585. };
  586. model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
  587. button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
  588. CGRectGetMaxY(loginFrame) + 20,
  589. CGRectGetWidth(loginFrame),
  590. 30);
  591. button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
  592. CGRectGetMaxY(button1.frame) + 15,
  593. CGRectGetWidth(loginFrame),
  594. 30);
  595. };
  596. return model;
  597. }
  598. #pragma mark - DIY 动画
  599. + (TXCustomModel *)buildAlertFadeModelWithButton1Title:(NSString *)button1Title
  600. target1:(id)target1
  601. selector1:(SEL)selector1
  602. button2Title:(NSString *)button2Title
  603. target2:(id)target2
  604. selector2:(SEL)selector2 {
  605. TXCustomModel *model = [self buildAlertPortraitModeWithButton1Title:button1Title
  606. target1:target1
  607. selector1:selector1
  608. button2Title:button2Title
  609. target2:target2
  610. selector2:selector2];
  611. CABasicAnimation *entryAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  612. entryAnimation.fromValue = @1.03;
  613. entryAnimation.toValue = @1;
  614. entryAnimation.duration = 0.25;
  615. entryAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
  616. model.entryAnimation = entryAnimation;
  617. CABasicAnimation *exitAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
  618. exitAnimation.fromValue = @1;
  619. exitAnimation.toValue = @0;
  620. exitAnimation.duration = 0.25;
  621. exitAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
  622. model.exitAnimation = exitAnimation;
  623. //背景本身就是渐变,可以省略不写 model.bgEntryAnimation、model.bgExitAnimation
  624. return model;
  625. }
  626. + (TXCustomModel *)buildAlertBounceModelWithButton1Title:(NSString *)button1Title
  627. target1:(id)target1
  628. selector1:(SEL)selector1
  629. button2Title:(NSString *)button2Title
  630. target2:(id)target2
  631. selector2:(SEL)selector2 {
  632. TXCustomModel *model = [self buildAlertPortraitModeWithButton1Title:button1Title
  633. target1:target1
  634. selector1:selector1
  635. button2Title:button2Title
  636. target2:target2
  637. selector2:selector2];
  638. CAKeyframeAnimation *entryAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
  639. entryAnimation.values = @[@0.01, @1.2, @0.9, @1];
  640. entryAnimation.keyTimes = @[@0, @0.4, @0.6, @1];
  641. entryAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
  642. entryAnimation.duration = 0.25;
  643. model.entryAnimation = entryAnimation;
  644. CAKeyframeAnimation *exitAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
  645. exitAnimation.values = @[@1, @1.2, @0.01];
  646. exitAnimation.keyTimes = @[@0, @0.4, @1];
  647. exitAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
  648. exitAnimation.duration = 0.25;
  649. model.exitAnimation = exitAnimation;
  650. //背景使用默认的渐变效果,可以省略不写 model.bgEntryAnimation、model.bgExitAnimation
  651. return model;
  652. }
  653. + (TXCustomModel *)buildAlertDropDownModelWithButton1Title:(NSString *)button1Title
  654. target1:(id)target1
  655. selector1:(SEL)selector1
  656. button2Title:(NSString *)button2Title
  657. target2:(id)target2
  658. selector2:(SEL)selector2 {
  659. TXCustomModel *model = [self buildAlertPortraitModeWithButton1Title:button1Title
  660. target1:target1
  661. selector1:selector1
  662. button2Title:button2Title
  663. target2:target2
  664. selector2:selector2];
  665. //提前设置好弹窗大小,弹窗是依赖于全屏布局,所以其父视图大小即为屏幕大小
  666. CGFloat width = UIScreen.mainScreen.bounds.size.width * 0.8;
  667. CGFloat height = width / 0.618;
  668. CGFloat x = (UIScreen.mainScreen.bounds.size.width - width) * 0.5;
  669. CGFloat y = (UIScreen.mainScreen.bounds.size.height - height) * 0.5;
  670. CGRect contentViewFrame = CGRectMake(x, y, width, height);
  671. model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
  672. return contentViewFrame;
  673. };
  674. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
  675. animation.values = @[@(-CGRectGetMaxY(contentViewFrame)), @20, @-10, @0];
  676. animation.keyTimes = @[@0, @0.5, @0.75, @1];
  677. animation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
  678. animation.duration = 0.25;
  679. model.entryAnimation = animation;
  680. //背景使用默认的渐变效果,可以省略不写 model.bgEntryAnimation、model.bgExitAnimation
  681. return model;
  682. }
  683. + (TXCustomModel *)buildFadeModelWithButton1Title:(NSString *)button1Title
  684. target1:(id)target1
  685. selector1:(SEL)selector1
  686. button2Title:(NSString *)button2Title
  687. target2:(id)target2
  688. selector2:(SEL)selector2 {
  689. TXCustomModel *model = [self buildFullScreenPortraitModelWithButton1Title:button1Title
  690. target1:target1
  691. selector1:selector1
  692. button2Title:button2Title
  693. target2:target2
  694. selector2:selector2];
  695. CABasicAnimation *entryAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
  696. entryAnimation.fromValue = @0.5;
  697. entryAnimation.toValue = @1;
  698. entryAnimation.duration = 0.25;
  699. entryAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
  700. model.entryAnimation = entryAnimation;
  701. CABasicAnimation *exitAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
  702. exitAnimation.fromValue = @1;
  703. exitAnimation.toValue = @0;
  704. exitAnimation.duration = 0.25;
  705. exitAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
  706. model.exitAnimation = exitAnimation;
  707. return model;
  708. }
  709. + (TXCustomModel *)buildScaleModelWithButton1Title:(NSString *)button1Title
  710. target1:(id)target1
  711. selector1:(SEL)selector1
  712. button2Title:(NSString *)button2Title
  713. target2:(id)target2
  714. selector2:(SEL)selector2 {
  715. TXCustomModel *model = [self buildFullScreenPortraitModelWithButton1Title:button1Title
  716. target1:target1
  717. selector1:selector1
  718. button2Title:button2Title
  719. target2:target2
  720. selector2:selector2];
  721. CABasicAnimation *entryAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  722. entryAnimation.fromValue = @0;
  723. entryAnimation.toValue = @1;
  724. entryAnimation.duration = 0.25;
  725. entryAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  726. model.entryAnimation = entryAnimation;
  727. CABasicAnimation *exitAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  728. exitAnimation.fromValue = @1;
  729. exitAnimation.toValue = @0;
  730. exitAnimation.duration = 0.25;
  731. exitAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  732. model.exitAnimation = exitAnimation;
  733. return model;
  734. }
  735. @end