123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812 |
- //
- // PNSBuildModelUtils.m
- // ATAuthSceneDemo
- //
- // Created by 刘超的MacBook on 2020/8/6.
- // Copyright © 2020 刘超的MacBook. All rights reserved.
- //
- #import "PNSBuildModelUtils.h"
- @implementation PNSBuildModelUtils
- + (TXCustomModel *)buildModelWithStyle:(PNSBuildModelStyle)style
- button1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = nil;
- switch (style) {
- case PNSBuildModelStylePortrait:
- model = [self buildFullScreenPortraitModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSBuildModelStyleLandscape:
- model = [self buildFullScreenLandscapeModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSBuildModelStyleAutorotate:
- model = [self buildFullScreenAutorotateModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSBuildModelStyleAlertPortrait:
- model = [self buildAlertPortraitModeWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSBuildModelStyleAlertLandscape:
- model = [self buildAlertLandscapeModeWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSBuildModelStyleAlertAutorotate:
- model = [self buildAlertAutorotateModeWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSBuildModelStyleSheetPortrait:
- model = [self buildSheetPortraitModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSDIYAlertPortraitFade:
- model = [self buildAlertFadeModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSDIYAlertPortraitBounce:
- model = [self buildAlertBounceModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSDIYAlertPortraitDropDown:
- model = [self buildAlertDropDownModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSDIYPortraitFade:
- model = [self buildFadeModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- case PNSDIYPortraitScale:
- model = [self buildScaleModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
- break;
- default:
- break;
- }
- return model;
- }
- #pragma mark - 全屏相关
- + (TXCustomModel *)buildFullScreenPortraitModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
- model.navColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
- model.logoImage = [UIImage imageNamed:@"taobao"];
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame),
- 30);
-
- button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(button1.frame) + 15,
- CGRectGetWidth(loginFrame),
- 30);
- };
- return model;
- }
- + (TXCustomModel *)buildFullScreenLandscapeModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscape;
- model.navColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
- model.logoImage = [UIImage imageNamed:@"taobao"];
- model.sloganIsHidden = YES;
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
-
- model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = 80;
- frame.size.height = 80;
- frame.origin.y = 15;
- frame.origin.x = (superViewSize.width - 80) * 0.5;
- return frame;
- };
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 15 + 80 + 15;
- return frame;
- };
-
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 110 + 30 + 20;
- return frame;
- };
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
-
- button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
- CGRectGetMinY(button1.frame),
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
- };
- return model;
- }
- + (TXCustomModel *)buildFullScreenAutorotateModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskAllButUpsideDown;
- model.navColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
- model.logoImage = [UIImage imageNamed:@"taobao"];
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
-
- model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = 80;
- frame.size.height = 80;
- frame.origin.y = screenSize.height > screenSize.width ? 30 : 15;
- frame.origin.x = (superViewSize.width - 80) * 0.5;
- return frame;
- };
- model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.size.width = superViewSize.width - 40;
- frame.size.height = 20;
- frame.origin.x = 20;
- frame.origin.y = 20 + 80 + 20;
- return frame;
- } else {
- return CGRectZero;
- }
- };
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.origin.y = 130 + 20 + 15;
- } else {
- frame.origin.y = 15 + 80 + 15;
- }
- return frame;
- };
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.origin.y = 170 + 30 + 20;
- } else {
- frame.origin.y = 110 + 30 + 20;
- }
- return frame;
- };
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- if (screenSize.height > screenSize.width) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame),
- 30);
-
- button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(button1.frame) + 15,
- CGRectGetWidth(loginFrame),
- 30);
- } else {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
-
- button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
- CGRectGetMinY(button1.frame),
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
- }
- };
- return model;
- }
- #pragma mark - 弹窗
- + (TXCustomModel *)buildAlertPortraitModeWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
- model.alertCornerRadiusArray = @[@10, @10, @10, @10];
- model.alertTitleBarColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
- model.logoImage = [UIImage imageNamed:@"taobao"];
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
-
- model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = superViewSize.width * 0.8;
- frame.size.height = frame.size.width / 0.618;
- frame.origin.x = (superViewSize.width - frame.size.width) * 0.5;
- frame.origin.y = (superViewSize.height - frame.size.height) * 0.5;
- return frame;
- };
- model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = 80;
- frame.size.height = 80;
- frame.origin.y = 20;
- frame.origin.x = (superViewSize.width - 80) * 0.5;
- return frame;
- };
- model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 20 + 80 + 20;
- return frame;
- };
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 120 + 20 + 15;
- return frame;
- };
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 155 + 20 + 30;
- return frame;
- };
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame),
- 30);
-
- button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(button1.frame) + 15,
- CGRectGetWidth(loginFrame),
- 30);
- };
- return model;
- }
- + (TXCustomModel *)buildAlertLandscapeModeWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscape;
- model.alertCornerRadiusArray = @[@10, @10, @10, @10];
- model.alertTitleBarColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
- model.logoIsHidden = YES;
- model.sloganIsHidden = YES;
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
-
- model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.height = superViewSize.height * 0.8;
- frame.size.width = frame.size.height / 0.618;
- frame.origin.x = (superViewSize.width - frame.size.width) * 0.5;
- frame.origin.y = (superViewSize.height - frame.size.height) * 0.5;
- return frame;
- };
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 30;
- return frame;
- };
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 30 + 20 + 30;
- return frame;
- };
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
-
- button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
- CGRectGetMinY(button1.frame),
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
- };
- return model;
- }
- + (TXCustomModel *)buildAlertAutorotateModeWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskAllButUpsideDown;
- model.alertCornerRadiusArray = @[@10, @10, @10, @10];
- model.alertTitleBarColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
- model.logoImage = [UIImage imageNamed:@"taobao"];
- model.sloganIsHidden = YES;
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"自定义协议", @"https://www.taobao.com"];
-
- model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.size.width = superViewSize.width * 0.8;
- frame.size.height = frame.size.width / 0.618;
- } else {
- frame.size.height = superViewSize.height * 0.8;
- frame.size.width = frame.size.height / 0.618;
- }
- frame.origin.x = (superViewSize.width - frame.size.width) * 0.5;
- frame.origin.y = (superViewSize.height - frame.size.height) * 0.5;
- return frame;
- };
- model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.size.width = 80;
- frame.size.height = 80;
- frame.origin.y = 20;
- frame.origin.x = (superViewSize.width - 80) * 0.5;
- } else {
- frame = CGRectZero;
- }
- return frame;
- };
- model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.size.height = 20;
- frame.size.width = superViewSize.width - 40;
- frame.origin.x = 20;
- frame.origin.y = 20 + 80 + 20;
- } else {
- frame = CGRectZero;
- }
- return frame;
- };
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.origin.y = 120 + 20 + 15;
- } else {
- frame.origin.y = 30;
- }
- return frame;
- };
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- if (screenSize.height > screenSize.width) {
- frame.origin.y = 155 + 20 + 30;
- } else {
- frame.origin.y = 30 + 20 + 30;
- }
- return frame;
- };
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- if (screenSize.height > screenSize.width) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame),
- 30);
-
- button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(button1.frame) + 15,
- CGRectGetWidth(loginFrame),
- 30);
- } else {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
-
- button2.frame = CGRectMake(CGRectGetMaxX(button1.frame),
- CGRectGetMinY(button1.frame),
- CGRectGetWidth(loginFrame) * 0.5,
- 30);
- }
- };
- return model;
- }
- #pragma mark - 底部弹窗
- + (TXCustomModel *)buildSheetPortraitModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
- TXCustomModel *model = [[TXCustomModel alloc] init];
- model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
- model.alertCornerRadiusArray = @[@10, @0, @0, @10];
- model.alertTitleBarColor = [UIColor orangeColor];
- NSDictionary *attributes = @{
- NSForegroundColorAttributeName : [UIColor whiteColor],
- NSFontAttributeName : [UIFont systemFontOfSize:20.0]
- };
- model.alertTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes];
- model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
- model.logoImage = [UIImage imageNamed:@"taobao"];
- model.changeBtnIsHidden = YES;
- model.privacyOne = @[@"协议1", @"https://www.taobao.com"];
-
- model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = superViewSize.width;
- frame.size.height = 460;
- frame.origin.x = 0;
- frame.origin.y = superViewSize.height - frame.size.height;
- return frame;
- };
- model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = 80;
- frame.size.height = 80;
- frame.origin.y = 20;
- frame.origin.x = (superViewSize.width - 80) * 0.5;
- return frame;
- };
- model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 20 + 80 + 20;
- return frame;
- };
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 120 + 20 + 15;
- return frame;
- };
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = 155 + 20 + 30;
- return frame;
- };
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button1 setTitle:button1Title forState:UIControlStateNormal];
- [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside];
-
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
- [button2 setTitle:button2Title forState:UIControlStateNormal];
- [button2 addTarget:target2 action:selector2 forControlEvents:UIControlEventTouchUpInside];
-
- model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
- [superCustomView addSubview:button1];
- [superCustomView addSubview:button2];
- };
- model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) {
- button1.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(loginFrame) + 20,
- CGRectGetWidth(loginFrame),
- 30);
-
- button2.frame = CGRectMake(CGRectGetMinX(loginFrame),
- CGRectGetMaxY(button1.frame) + 15,
- CGRectGetWidth(loginFrame),
- 30);
- };
- return model;
- }
- #pragma mark - DIY 动画
- + (TXCustomModel *)buildAlertFadeModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
-
- TXCustomModel *model = [self buildAlertPortraitModeWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
-
- CABasicAnimation *entryAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- entryAnimation.fromValue = @1.03;
- entryAnimation.toValue = @1;
- entryAnimation.duration = 0.25;
- entryAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
- model.entryAnimation = entryAnimation;
-
- CABasicAnimation *exitAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
- exitAnimation.fromValue = @1;
- exitAnimation.toValue = @0;
- exitAnimation.duration = 0.25;
- exitAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
- model.exitAnimation = exitAnimation;
-
- //背景本身就是渐变,可以省略不写 model.bgEntryAnimation、model.bgExitAnimation
- return model;
- }
- + (TXCustomModel *)buildAlertBounceModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
-
- TXCustomModel *model = [self buildAlertPortraitModeWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
-
- CAKeyframeAnimation *entryAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
- entryAnimation.values = @[@0.01, @1.2, @0.9, @1];
- entryAnimation.keyTimes = @[@0, @0.4, @0.6, @1];
- entryAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
- entryAnimation.duration = 0.25;
- model.entryAnimation = entryAnimation;
-
- CAKeyframeAnimation *exitAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
- exitAnimation.values = @[@1, @1.2, @0.01];
- exitAnimation.keyTimes = @[@0, @0.4, @1];
- exitAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
- exitAnimation.duration = 0.25;
- model.exitAnimation = exitAnimation;
-
- //背景使用默认的渐变效果,可以省略不写 model.bgEntryAnimation、model.bgExitAnimation
- return model;
- }
- + (TXCustomModel *)buildAlertDropDownModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
-
- TXCustomModel *model = [self buildAlertPortraitModeWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
-
- //提前设置好弹窗大小,弹窗是依赖于全屏布局,所以其父视图大小即为屏幕大小
- CGFloat width = UIScreen.mainScreen.bounds.size.width * 0.8;
- CGFloat height = width / 0.618;
- CGFloat x = (UIScreen.mainScreen.bounds.size.width - width) * 0.5;
- CGFloat y = (UIScreen.mainScreen.bounds.size.height - height) * 0.5;
- CGRect contentViewFrame = CGRectMake(x, y, width, height);
-
- model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- return contentViewFrame;
- };
-
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
- animation.values = @[@(-CGRectGetMaxY(contentViewFrame)), @20, @-10, @0];
- animation.keyTimes = @[@0, @0.5, @0.75, @1];
- animation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
- animation.duration = 0.25;
- model.entryAnimation = animation;
-
- //背景使用默认的渐变效果,可以省略不写 model.bgEntryAnimation、model.bgExitAnimation
- return model;
- }
- + (TXCustomModel *)buildFadeModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
-
- TXCustomModel *model = [self buildFullScreenPortraitModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
-
- CABasicAnimation *entryAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
- entryAnimation.fromValue = @0.5;
- entryAnimation.toValue = @1;
- entryAnimation.duration = 0.25;
- entryAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
- model.entryAnimation = entryAnimation;
-
- CABasicAnimation *exitAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
- exitAnimation.fromValue = @1;
- exitAnimation.toValue = @0;
- exitAnimation.duration = 0.25;
- exitAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
- model.exitAnimation = exitAnimation;
-
- return model;
- }
- + (TXCustomModel *)buildScaleModelWithButton1Title:(NSString *)button1Title
- target1:(id)target1
- selector1:(SEL)selector1
- button2Title:(NSString *)button2Title
- target2:(id)target2
- selector2:(SEL)selector2 {
-
- TXCustomModel *model = [self buildFullScreenPortraitModelWithButton1Title:button1Title
- target1:target1
- selector1:selector1
- button2Title:button2Title
- target2:target2
- selector2:selector2];
-
- CABasicAnimation *entryAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- entryAnimation.fromValue = @0;
- entryAnimation.toValue = @1;
- entryAnimation.duration = 0.25;
- entryAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
- model.entryAnimation = entryAnimation;
-
- CABasicAnimation *exitAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- exitAnimation.fromValue = @1;
- exitAnimation.toValue = @0;
- exitAnimation.duration = 0.25;
- exitAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- model.exitAnimation = exitAnimation;
-
- return model;
- }
- @end
|