diff --git a/TYAlertControllerDemo.xcodeproj/project.pbxproj b/TYAlertControllerDemo.xcodeproj/project.pbxproj index ebc98fe..496b767 100644 --- a/TYAlertControllerDemo.xcodeproj/project.pbxproj +++ b/TYAlertControllerDemo.xcodeproj/project.pbxproj @@ -285,7 +285,7 @@ TargetAttributes = { D358541D1B9532D700B5FA1F = { CreatedOnToolsVersion = 6.4; - DevelopmentTeam = ZW52Q3KXX4; + DevelopmentTeam = YVL7699HA5; }; D35854361B9532D700B5FA1F = { CreatedOnToolsVersion = 6.4; @@ -298,6 +298,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -488,6 +489,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEVELOPMENT_TEAM = YVL7699HA5; INFOPLIST_FILE = TYAlertControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie.xcuserdatad/UserInterfaceState.xcuserstate b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..fcd1b29 Binary files /dev/null and b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie_vendor.xcuserdatad/IDEFindNavigatorScopes.plist b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie_vendor.xcuserdatad/IDEFindNavigatorScopes.plist new file mode 100644 index 0000000..5dd5da8 --- /dev/null +++ b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie_vendor.xcuserdatad/IDEFindNavigatorScopes.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie_vendor.xcuserdatad/UserInterfaceState.xcuserstate b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie_vendor.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..a16a72e Binary files /dev/null and b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/shenruijie_vendor.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TYAlertControllerDemo.xcodeproj/xcuserdata/shenruijie.xcuserdatad/xcschemes/xcschememanagement.plist b/TYAlertControllerDemo.xcodeproj/xcuserdata/shenruijie.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..7039510 --- /dev/null +++ b/TYAlertControllerDemo.xcodeproj/xcuserdata/shenruijie.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + TYAlertControllerDemo.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/TYAlertControllerDemo.xcodeproj/xcuserdata/shenruijie_vendor.xcuserdatad/xcschemes/xcschememanagement.plist b/TYAlertControllerDemo.xcodeproj/xcuserdata/shenruijie_vendor.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..7039510 --- /dev/null +++ b/TYAlertControllerDemo.xcodeproj/xcuserdata/shenruijie_vendor.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + TYAlertControllerDemo.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h index 11e185e..2329bd4 100644 --- a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h +++ b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h @@ -14,16 +14,40 @@ @property (nonatomic, strong) UIView *backgroundView; @property (nonatomic, assign) BOOL backgoundTapDismissEnable; // default NO -@property (nonatomic, assign) CGFloat alertViewOriginY; // default center Y -@property (nonatomic, assign) CGFloat alertViewEdging; // default 15 + + +/** 2019-10-04 12:13:56 + 取值优先级为 ( 数字越小, 优先级越高 ) + 1. NSLayoutAttributeWidth, 如果有宽度layout,则以layout为准 + 2. 主动赋值了alertViewWidth,则以_alertViewWidth为准 + 3. alertView.size != {0 , 0} , 则以 alertView.size 为准 + 4. superView.width - 2 * 15 + */ +@property (nonatomic, assign) CGFloat alertViewWidth; + +/** 2019-10-04 12:22:41 + 取值优先级为 ( 数字越小, 优先级越高 ) + 1. NSLayoutAttributeHeight, 如果有宽度layout,则以layout为准 + 2. 主动赋值了alertViewHeight属性,则以_alertViewHeight为准 + 3. alertView.size != {0 , 0} , 则以 alertView.size 为准 + 4. 200 +*/ +@property (nonatomic, assign) CGFloat alertViewHeight; + +/** 2019-10-04 12:24:03 + 1. 主动赋值了alertViewCenter,则以_alertViewCenter为准 + 2. alertView.size != {0 , 0}, 则视为想要使用frame进行约束,赋值CGPointMake(CGRectGetMidX(_alertView.frame), CGRectGetMidY(_alertView.frame)) + 3.kCurrentWindow.center + */ +@property (nonatomic, assign) CGPoint alertViewCenter; +(void)showAlertViewWithView:(UIView *)alertView; + (void)showAlertViewWithView:(UIView *)alertView backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; -+(void)showAlertViewWithView:(UIView *)alertView originY:(CGFloat)originY; ++(void)showAlertViewWithView:(UIView *)alertView center:(CGPoint)center; -+(void)showAlertViewWithView:(UIView *)alertView originY:(CGFloat)originY backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; ++ (void)showAlertViewWithView:(UIView *)alertView center:(CGPoint)center backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; + (instancetype)alertViewWithView:(UIView *)alertView; diff --git a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m index 98989c1..08900a9 100644 --- a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m +++ b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m @@ -25,7 +25,6 @@ - (instancetype)initWithFrame:(CGRect)frame self.backgroundColor = [UIColor clearColor]; _backgoundTapDismissEnable = NO; - _alertViewEdging = 15; [self addBackgroundView]; @@ -61,16 +60,16 @@ + (void)showAlertViewWithView:(UIView *)alertView backgoundTapDismissEnable:(BOO [showTipView show]; } -+ (void)showAlertViewWithView:(UIView *)alertView originY:(CGFloat)originY ++ (void)showAlertViewWithView:(UIView *)alertView center:(CGPoint)center { [self showAlertViewWithView:alertView - originY:originY backgoundTapDismissEnable:NO]; + center:center backgoundTapDismissEnable:NO]; } -+ (void)showAlertViewWithView:(UIView *)alertView originY:(CGFloat)originY backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable ++ (void)showAlertViewWithView:(UIView *)alertView center:(CGPoint)center backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable { TYShowAlertView *showTipView = [self alertViewWithView:alertView]; - showTipView.alertViewOriginY = originY; + showTipView.alertViewCenter = center; showTipView.backgoundTapDismissEnable = backgoundTapDismissEnable; [showTipView show]; } @@ -114,34 +113,51 @@ - (void)didMoveToSuperview - (void)layoutAlertView { _alertView.translatesAutoresizingMaskIntoConstraints = NO; - // center X - [self addConstraintCenterXToView:_alertView centerYToView:nil]; - // width, height - if (!CGSizeEqualToSize(_alertView.frame.size,CGSizeZero)) { - [_alertView addConstraintWidth:CGRectGetWidth(_alertView.frame) height:CGRectGetHeight(_alertView.frame)]; - - }else { - BOOL findAlertViewWidthConstraint = NO; - for (NSLayoutConstraint *constraint in _alertView.constraints) { - if (constraint.firstAttribute == NSLayoutAttributeWidth) { - findAlertViewWidthConstraint = YES; - break; - } - } - - if (!findAlertViewWidthConstraint) { - [_alertView addConstraintWidth:CGRectGetWidth(self.superview.frame)-2*_alertViewEdging height:0]; - } + BOOL findAlertViewWidthConstraint = NO; + BOOL findAlertViewHeightConstraint = NO; + BOOL hasSetFrame = !CGSizeEqualToSize(_alertView.frame.size,CGSizeZero); + + /**2019-10-04 12:10:15 如果没有人为设置_alertViewCenter, 则取frame的对应的center*/ + if (CGPointEqualToPoint(_alertViewCenter, CGPointZero) && hasSetFrame) { + _alertViewCenter = CGPointMake(CGRectGetMidX(_alertView.frame), CGRectGetMidY(_alertView.frame)); } - // topY - NSLayoutConstraint *alertViewCenterYConstraint = [self addConstraintCenterYToView:_alertView constant:0]; + /**2019-10-04 12:11:52 alertViewCenter*/ + [self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_alertView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:-_alertViewCenter.x]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual + toItem:_alertView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:-_alertViewCenter.y]]; + + /**2019-10-04 13:17:47 alertViewWidth & _alertViewHeight*/ + for (NSLayoutConstraint *constraint in _alertView.constraints) { + if (constraint.firstAttribute == NSLayoutAttributeWidth) { + findAlertViewWidthConstraint = YES; + _alertViewWidth = constraint.constant; + }else if (constraint.firstAttribute == NSLayoutAttributeHeight){ + findAlertViewHeightConstraint = YES; + _alertViewHeight = constraint.constant; + } + } - if (_alertViewOriginY > 0) { - [_alertView layoutIfNeeded]; - alertViewCenterYConstraint.constant = _alertViewOriginY - (CGRectGetHeight(self.superview.frame) - CGRectGetHeight(_alertView.frame))/2; + if (!findAlertViewWidthConstraint && !_alertViewWidth) { + /**2019-10-04 12:10:15 如果没有人为设置_alertViewWidth, 则从frame中取*/ + if (hasSetFrame) { + _alertViewWidth = _alertView.frame.size.width; + }else{ + _alertViewWidth = CGRectGetWidth(self.superview.frame)-2*15; + } + [_alertView addConstraintWidth:_alertViewWidth height:0]; } + + if (!findAlertViewHeightConstraint && !_alertViewHeight) { + /**2019-10-04 12:10:15 如果没有人为设置_alertViewHeight, default:200*/ + if (hasSetFrame) { + _alertViewHeight = _alertView.frame.size.height; + }else{ + _alertViewWidth = 200; + } + [_alertView addConstraintWidth:0 height:_alertViewHeight]; + } } #pragma mark - add Gesture @@ -183,6 +199,7 @@ - (void)hide _alertView.transform = CGAffineTransformScale(_alertView.transform,0.1,0.1); self.alpha = 0; } completion:^(BOOL finished) { + _alertView.transform = CGAffineTransformIdentity; [self removeFromSuperview]; }]; } diff --git a/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.h b/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.h index 5907ddb..76463e1 100644 --- a/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.h +++ b/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.h @@ -38,9 +38,9 @@ // backgoundTapDismissEnable default NO - (void)showInWindowWithBackgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; -- (void)showInWindowWithOriginY:(CGFloat)OriginY; +- (void)showInWindowWithCenter:(CGPoint)center; -- (void)showInWindowWithOriginY:(CGFloat)OriginY backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; +- (void)showInWindowWithCenter:(CGPoint)center backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; #pragma mark - hide diff --git a/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.m b/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.m index f8895ed..fd8e0f2 100644 --- a/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.m +++ b/TYAlertControllerDemo/TYAlertController/UIView+TYAlertView.m @@ -47,17 +47,17 @@ - (void)showInWindowWithBackgoundTapDismissEnable:(BOOL)backgoundTapDismissEnabl [TYShowAlertView showAlertViewWithView:self backgoundTapDismissEnable:backgoundTapDismissEnable]; } -- (void)showInWindowWithOriginY:(CGFloat)OriginY +- (void)showInWindowWithCenter:(CGPoint)center { - [self showInWindowWithOriginY:OriginY backgoundTapDismissEnable:NO]; + [self showInWindowWithCenter:center backgoundTapDismissEnable:NO]; } -- (void)showInWindowWithOriginY:(CGFloat)OriginY backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable +- (void)showInWindowWithCenter:(CGPoint)center backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable { if (self.superview) { [self removeFromSuperview]; } - [TYShowAlertView showAlertViewWithView:self originY:OriginY backgoundTapDismissEnable:backgoundTapDismissEnable]; + [TYShowAlertView showAlertViewWithView:self center:center backgoundTapDismissEnable:backgoundTapDismissEnable]; } - (void)hideInWindow diff --git a/TYAlertControllerDemo/ViewController.m b/TYAlertControllerDemo/ViewController.m index 39182f6..260aca3 100644 --- a/TYAlertControllerDemo/ViewController.m +++ b/TYAlertControllerDemo/ViewController.m @@ -15,6 +15,10 @@ #import "SettingModelView.h" #import "ShareView.h" +#define kScreenWidth [UIScreen mainScreen].bounds.size.width +#define kScreenHeight [UIScreen mainScreen].bounds.size.height +#define kCurrentWindowCenter [UIApplication sharedApplication].keyWindow.center + @interface ViewController () @end @@ -158,7 +162,7 @@ - (IBAction)showAlertViewInWindowAction:(id)sender { }]]; // first way to show ,use UIView Category - [alertView showInWindowWithOriginY:200 backgoundTapDismissEnable:YES]; + [alertView showInWindowWithCenter:kCurrentWindowCenter backgoundTapDismissEnable:YES]; // second way to show //[TYShowAlertView showAlertViewWithView:alertView originY:200 backgoundTapDismissEnable:YES]; @@ -168,7 +172,7 @@ - (IBAction)customViewInWindowAction:(id)sender { ShareView *shareView = [ShareView createViewFromNib]; // use UIView Category - [shareView showInWindow]; + [shareView showInWindowWithCenter:CGPointMake(kScreenWidth / 2.0, 380)]; } - (void)didReceiveMemoryWarning {