diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..cf8b2c8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2016 tany + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md index 273e9e1..b6417d6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # TYAlertController Powerful, Easy to use alertView or popupView on controller and window, support blur effect, custom view and custom animation, use aotolayout.support iphone, ipad . +## CocoaPods +``` +pod 'TYAlertController' +``` + ### ScreenShot ![image](https://github.com/12207480/TYAlertController/blob/master/screenshot/TYAlertControllerDemo.gif) @@ -18,7 +23,19 @@ Powerful, Easy to use alertView or popupView on controller and window, support b ### usege demo -* show in controller (tow way) +* alertView lifecycle block +```objc +// alertView lifecycle block +@property (copy, nonatomic) void (^viewWillShowHandler)(UIView *alertView); +@property (copy, nonatomic) void (^viewDidShowHandler)(UIView *alertView); +@property (copy, nonatomic) void (^viewWillHideHandler)(UIView *alertView); +@property (copy, nonatomic) void (^viewDidHideHandler)(UIView *alertView); + +// dismiss controller completed block +@property (nonatomic, copy) void (^dismissComplete)(void); +``` + +* show in controller (tow way)(recommend) ```objc TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt text and textfiled. "]; @@ -67,5 +84,4 @@ TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message: ### Contact if you find bug,please pull reqeust me
-if you have good idea,contact me, Email:122074809@qq.com diff --git a/TYAlertController.podspec b/TYAlertController.podspec new file mode 100644 index 0000000..d6a8b29 --- /dev/null +++ b/TYAlertController.podspec @@ -0,0 +1,24 @@ +Pod::Spec.new do |s| +# 名称 使用的时候pod search [name] +s.name = "TYAlertController" +# 代码库的版本 +s.version = "1.2.0" +# 简介 +s.summary = "Powerful, Easy to use alertview or popup view on controller and window, support blur effects,custom view and animation." +# 主页 +s.homepage = "https://github.com/12207480/TYAlertController" +# 许可证书类型,要和仓库的LICENSE 的类型一致 +s.license = { :type => 'MIT', :file => 'LICENSE' } +# 作者名称 和 邮箱 +s.author = { "tany" => "122074809@qq.com" } +# 作者主页 s.social_media_url ="" +# 代码库最低支持的版本 +s.platform = :ios, "7.0" +# 代码的Clone 地址 和 tag 版本 +s.source = { :git => "https://github.com/12207480/TYAlertController.git", :tag => s.version.to_s } +# 如果使用pod 需要导入哪些资源 +s.source_files = "TYAlertControllerDemo/TYAlertController/**/*.{h,m}" +# s.resources = "**/*/*.bundle" +# 框架是否使用的ARC +s.requires_arc = true +end diff --git a/TYAlertControllerDemo.xcodeproj/project.pbxproj b/TYAlertControllerDemo.xcodeproj/project.pbxproj index 6891071..ebc98fe 100644 --- a/TYAlertControllerDemo.xcodeproj/project.pbxproj +++ b/TYAlertControllerDemo.xcodeproj/project.pbxproj @@ -285,6 +285,7 @@ TargetAttributes = { D358541D1B9532D700B5FA1F = { CreatedOnToolsVersion = 6.4; + DevelopmentTeam = ZW52Q3KXX4; }; D35854361B9532D700B5FA1F = { CreatedOnToolsVersion = 6.4; @@ -414,7 +415,8 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -433,7 +435,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -458,7 +460,8 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; @@ -471,7 +474,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -483,10 +486,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = TYAlertControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.tanyang.TYAlertControllerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -494,10 +501,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = TYAlertControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.tanyang.TYAlertControllerDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Release; }; diff --git a/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/tanyang.xcuserdatad/UserInterfaceState.xcuserstate b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/tanyang.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..a0c9687 Binary files /dev/null and b/TYAlertControllerDemo.xcodeproj/project.xcworkspace/xcuserdata/tanyang.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TYAlertControllerDemo/Images.xcassets/AppIcon.appiconset/Contents.json b/TYAlertControllerDemo/Images.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..1d060ed 100644 --- a/TYAlertControllerDemo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/TYAlertControllerDemo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/TYAlertControllerDemo/ShareView.m b/TYAlertControllerDemo/ShareView.m index 65dc083..1b0eec4 100644 --- a/TYAlertControllerDemo/ShareView.m +++ b/TYAlertControllerDemo/ShareView.m @@ -11,7 +11,7 @@ @implementation ShareView -- (IBAction)cancleAction:(id)sender { +- (IBAction)cancelAction:(id)sender { // hide view,or dismiss controller [self hideView]; } diff --git a/TYAlertControllerDemo/ShareView.xib b/TYAlertControllerDemo/ShareView.xib index 99abd08..4843546 100644 --- a/TYAlertControllerDemo/ShareView.xib +++ b/TYAlertControllerDemo/ShareView.xib @@ -1,8 +1,7 @@ - + - - + @@ -13,7 +12,6 @@ - - - diff --git a/TYAlertControllerDemo/TYAlertController/TYAlertController+TransitionAnimate.m b/TYAlertControllerDemo/TYAlertController/TYAlertController+TransitionAnimate.m index 031590c..9c509f4 100644 --- a/TYAlertControllerDemo/TYAlertController/TYAlertController+TransitionAnimate.m +++ b/TYAlertControllerDemo/TYAlertController/TYAlertController+TransitionAnimate.m @@ -25,7 +25,7 @@ @implementation TYAlertController (TransitionAnimate) case TYAlertTransitionAnimationDropDown: return [TYAlertDropDownAnimation alertAnimationIsPresenting:YES]; case TYAlertTransitionAnimationCustom: - return [self.class alertAnimationIsPresenting:YES preferredStyle:self.preferredStyle]; + return [self.transitionAnimationClass alertAnimationIsPresenting:YES preferredStyle:self.preferredStyle]; default: return nil; } @@ -41,7 +41,7 @@ @implementation TYAlertController (TransitionAnimate) case TYAlertTransitionAnimationDropDown: return [TYAlertDropDownAnimation alertAnimationIsPresenting:NO]; case TYAlertTransitionAnimationCustom: - return [self.class alertAnimationIsPresenting:NO preferredStyle:self.preferredStyle]; + return [self.transitionAnimationClass alertAnimationIsPresenting:NO preferredStyle:self.preferredStyle]; default: return nil; } diff --git a/TYAlertControllerDemo/TYAlertController/TYAlertController.h b/TYAlertControllerDemo/TYAlertController/TYAlertController.h index 7ff97d4..583f8f5 100644 --- a/TYAlertControllerDemo/TYAlertController/TYAlertController.h +++ b/TYAlertControllerDemo/TYAlertController/TYAlertController.h @@ -42,7 +42,14 @@ typedef NS_ENUM(NSInteger, TYAlertTransitionAnimation) { @property (nonatomic, assign) CGFloat alertStyleEdging; // when width frame equal to 0,or no width constraint ,this proprty will use, default to 15 edge @property (nonatomic, assign) CGFloat actionSheetStyleEdging; // default 0 -@property (nonatomic, copy) void (^dismissComplete)(void); // dismiss controller completed block +// alertView lifecycle block +@property (copy, nonatomic) void (^viewWillShowHandler)(UIView *alertView); +@property (copy, nonatomic) void (^viewDidShowHandler)(UIView *alertView); +@property (copy, nonatomic) void (^viewWillHideHandler)(UIView *alertView); +@property (copy, nonatomic) void (^viewDidHideHandler)(UIView *alertView); + +// dismiss controller completed block +@property (nonatomic, copy) void (^dismissComplete)(void); + (instancetype)alertControllerWithAlertView:(UIView *)alertView; diff --git a/TYAlertControllerDemo/TYAlertController/TYAlertController.m b/TYAlertControllerDemo/TYAlertController/TYAlertController.m index cc7267c..8493455 100644 --- a/TYAlertControllerDemo/TYAlertController/TYAlertController.m +++ b/TYAlertControllerDemo/TYAlertController/TYAlertController.m @@ -121,6 +121,42 @@ - (void)viewDidLoad { } +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + if (_viewWillShowHandler) { + _viewWillShowHandler(_alertView); + } +} + +- (void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + + if (_viewDidShowHandler) { + _viewDidShowHandler(_alertView); + } +} + +- (void)viewWillDisappear:(BOOL)animated +{ + [super viewWillDisappear:animated]; + + if (_viewWillHideHandler) { + _viewWillHideHandler(_alertView); + } +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + + if (_viewDidHideHandler) { + _viewDidHideHandler(_alertView); + } +} + - (void)addBackgroundView { if (_backgroundView == nil) { @@ -130,7 +166,7 @@ - (void)addBackgroundView } _backgroundView.translatesAutoresizingMaskIntoConstraints = NO; [self.view insertSubview:_backgroundView atIndex:0]; - [self.view addConstraintToView:_backgroundView edageInset:UIEdgeInsetsZero]; + [self.view addConstraintToView:_backgroundView edgeInset:UIEdgeInsetsZero]; } - (void)setBackgroundView:(UIView *)backgroundView @@ -140,7 +176,7 @@ - (void)setBackgroundView:(UIView *)backgroundView } else if (_backgroundView != backgroundView) { backgroundView.translatesAutoresizingMaskIntoConstraints = NO; [self.view insertSubview:backgroundView aboveSubview:_backgroundView]; - [self.view addConstraintToView:backgroundView edageInset:UIEdgeInsetsZero]; + [self.view addConstraintToView:backgroundView edgeInset:UIEdgeInsetsZero]; backgroundView.alpha = 0; [UIView animateWithDuration:0.3 animations:^{ backgroundView.alpha = 1; @@ -155,7 +191,8 @@ - (void)setBackgroundView:(UIView *)backgroundView - (void)addSingleTapGesture { self.view.userInteractionEnabled = YES; - + _backgroundView.userInteractionEnabled = YES; + UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)]; singleTap.enabled = _backgoundTapDismissEnable; @@ -209,7 +246,7 @@ - (void)configureAlertViewWidth { // width, height if (!CGSizeEqualToSize(_alertView.frame.size,CGSizeZero)) { - [_alertView addConstarintWidth:CGRectGetWidth(_alertView.frame) height:CGRectGetHeight(_alertView.frame)]; + [_alertView addConstraintWidth:CGRectGetWidth(_alertView.frame) height:CGRectGetHeight(_alertView.frame)]; }else { BOOL findAlertViewWidthConstraint = NO; @@ -221,7 +258,7 @@ - (void)configureAlertViewWidth } if (!findAlertViewWidthConstraint) { - [_alertView addConstarintWidth:CGRectGetWidth(self.view.frame)-2*_alertStyleEdging height:0]; + [_alertView addConstraintWidth:CGRectGetWidth(self.view.frame)-2*_alertStyleEdging height:0]; } } } @@ -231,7 +268,7 @@ - (void)configureAlertViewWidth - (void)layoutAlertStyleView { // center X - [self.view addConstraintCenterXToView:_alertView CenterYToView:nil]; + [self.view addConstraintCenterXToView:_alertView centerYToView:nil]; [self configureAlertViewWidth]; @@ -249,14 +286,20 @@ - (void)layoutAlertStyleView - (void)layoutActionSheetStyleView { - // center X - [self.view addConstraintCenterXToView:_alertView CenterYToView:nil]; + // remove width constaint + for (NSLayoutConstraint *constraint in _alertView.constraints) { + if (constraint.firstAttribute == NSLayoutAttributeWidth) { + [_alertView removeConstraint: constraint]; + break; + } + } - [self.view addConstarintWithView:_alertView topView:nil leftView:self.view bottomView:self.view rightView:self.view edageInset:UIEdgeInsetsMake(0, _actionSheetStyleEdging, 0, -_actionSheetStyleEdging)]; + // add edge constraint + [self.view addConstraintWithView:_alertView topView:nil leftView:self.view bottomView:self.view rightView:self.view edgeInset:UIEdgeInsetsMake(0, _actionSheetStyleEdging, 0, -_actionSheetStyleEdging)]; if (CGRectGetHeight(_alertView.frame) > 0) { // height - [_alertView addConstarintWidth:0 height:CGRectGetHeight(_alertView.frame)]; + [_alertView addConstraintWidth:0 height:CGRectGetHeight(_alertView.frame)]; } } @@ -272,24 +315,35 @@ - (void)singleTap:(UITapGestureRecognizer *)sender [self dismissViewControllerAnimated:YES]; } -#pragma mark - notifycation +#pragma mark - notification -- (void)keyboardWillShow:(NSNotification*)notification{ +- (void)keyboardWillShow:(NSNotification*)notification +{ CGRect keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; - CGFloat alertViewBottomEdge = CGRectGetHeight(self.view.frame) - CGRectGetMaxY(_alertView.frame); + CGFloat alertViewBottomEdge = (CGRectGetHeight(self.view.frame) - CGRectGetHeight(_alertView.frame))/2 - _alertViewCenterYOffset; + + //当开启热点时,向下偏移20px + //修复键盘遮挡问题 + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; CGFloat differ = CGRectGetHeight(keyboardRect) - alertViewBottomEdge; + + //修复:输入框获取焦点时,会重复刷新,导致输入框文章偏移一下 + if (_alertViewCenterYConstraint.constant == -differ -statusBarHeight) { + return; + } - if (differ > 0) { - _alertViewCenterYConstraint.constant = _alertViewCenterYOffset - differ; + if (differ >= 0) { + _alertViewCenterYConstraint.constant = _alertViewCenterYOffset - differ - statusBarHeight; [UIView animateWithDuration:0.25 animations:^{ [self.view layoutIfNeeded]; }]; } } -- (void)keyboardWillHide:(NSNotification*)notification{ - + +- (void)keyboardWillHide:(NSNotification*)notification +{ _alertViewCenterYConstraint.constant = _alertViewCenterYOffset; [UIView animateWithDuration:0.25 animations:^{ [self.view layoutIfNeeded]; @@ -305,7 +359,6 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; - NSLog(@"%@ dealloc",NSStringFromClass([self class])); } @end diff --git a/TYAlertControllerDemo/TYAlertController/TYAlertView.h b/TYAlertControllerDemo/TYAlertController/TYAlertView.h index c85eb87..793fcaa 100644 --- a/TYAlertControllerDemo/TYAlertController/TYAlertView.h +++ b/TYAlertControllerDemo/TYAlertController/TYAlertView.h @@ -10,7 +10,7 @@ typedef NS_ENUM(NSUInteger, TYAlertActionStyle) { TYAlertActionStyleDefault, - TYAlertActionStyleCancle, + TYAlertActionStyleCancel, TYAlertActionStyleDestructive, }; @@ -30,6 +30,7 @@ typedef NS_ENUM(NSUInteger, TYAlertActionStyle) { @property (nonatomic, weak, readonly) UILabel *titleLable; @property (nonatomic, weak, readonly) UILabel *messageLabel; +// alertView textfield array @property (nonatomic, strong, readonly) NSArray *textFieldArray; // default 280, if 0 don't add width constraint, @@ -46,20 +47,23 @@ typedef NS_ENUM(NSUInteger, TYAlertActionStyle) { @property (nonatomic, assign) CGFloat buttonHeight; @property (nonatomic, assign) CGFloat buttonSpace; @property (nonatomic, assign) CGFloat buttonContentViewEdge; +@property (nonatomic, assign) CGFloat buttonContentViewTop; @property (nonatomic, assign) CGFloat buttonCornerRadius; @property (nonatomic, strong) UIFont *buttonFont; @property (nonatomic, strong) UIColor *buttonDefaultBgColor; -@property (nonatomic, strong) UIColor *buttonCancleBgColor; +@property (nonatomic, strong) UIColor *buttonCancelBgColor; @property (nonatomic, strong) UIColor *buttonDestructiveBgColor; -// textFeild custom +// textField custom @property (nonatomic, strong) UIColor *textFieldBorderColor; @property (nonatomic, strong) UIColor *textFieldBackgroudColor; @property (nonatomic, strong) UIFont *textFieldFont; -@property (nonatomic, assign) CGFloat textFeildHeight; -@property (nonatomic, assign) CGFloat textFeildEdge; -@property (nonatomic, assign) CGFloat textFeildorderWidth; -@property (nonatomic, assign) CGFloat textFeildContentViewEdge; +@property (nonatomic, assign) CGFloat textFieldHeight; +@property (nonatomic, assign) CGFloat textFieldEdge; +@property (nonatomic, assign) CGFloat textFieldBorderWidth; +@property (nonatomic, assign) CGFloat textFieldContentViewEdge; + +@property (nonatomic, assign) BOOL clickedAutoHide; + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message; diff --git a/TYAlertControllerDemo/TYAlertController/TYAlertView.m b/TYAlertControllerDemo/TYAlertController/TYAlertView.m index e844ade..9eabc29 100644 --- a/TYAlertControllerDemo/TYAlertController/TYAlertView.m +++ b/TYAlertControllerDemo/TYAlertController/TYAlertView.m @@ -53,10 +53,10 @@ @interface TYAlertView () @property (nonatomic, weak) UILabel *titleLable; @property (nonatomic, weak) UILabel *messageLabel; -@property (nonatomic, weak) UIView *textFeildContentView; -@property (nonatomic, weak) NSLayoutConstraint *textFeildTopConstraint; -@property (nonatomic, strong) NSMutableArray *textFeilds; -@property (nonatomic, strong) NSMutableArray *textFeildSeparateViews; +@property (nonatomic, weak) UIView *textFieldContentView; +@property (nonatomic, weak) NSLayoutConstraint *textFieldTopConstraint; +@property (nonatomic, strong) NSMutableArray *textFields; +@property (nonatomic, strong) NSMutableArray *textFieldSeparateViews; // button content View @property (nonatomic, weak) UIView *buttonContentView; @@ -76,10 +76,10 @@ @interface TYAlertView () #define kButtonSpace 6 #define KButtonHeight 44 -#define kTextFeildOffset 10000 -#define kTextFeildHeight 29 -#define kTextFeildEdge 8 -#define KTextFeildBorderWidth 0.5 +#define kTextFieldOffset 10000 +#define kTextFieldHeight 29 +#define kTextFieldEdge 8 +#define KTextFieldBorderWidth 0.5 @implementation TYAlertView @@ -102,7 +102,7 @@ - (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { - if (self = [super init]) { + if (self = [self init]) { _titleLable.text = title; _messageLabel.text = message; @@ -120,6 +120,7 @@ + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message - (void)configureProperty { + _clickedAutoHide = YES; self.backgroundColor = [UIColor whiteColor]; _alertViewWidth = kAlertViewWidth; _contentViewSpace = kContentViewSpace; @@ -130,16 +131,17 @@ - (void)configureProperty _buttonHeight = KButtonHeight; _buttonSpace = kButtonSpace; _buttonContentViewEdge = kContentViewEdge; + _buttonContentViewTop = kContentViewSpace; _buttonCornerRadius = 4.0; - _buttonFont = [UIFont fontWithName:@"HelveticaNeue" size:18];; + _buttonFont = [UIFont fontWithName:@"HelveticaNeue" size:18]; _buttonDefaultBgColor = [UIColor colorWithRed:52/255.0 green:152/255.0 blue:219/255.0 alpha:1]; - _buttonCancleBgColor = [UIColor colorWithRed:127/255.0 green:140/255.0 blue:141/255.0 alpha:1]; + _buttonCancelBgColor = [UIColor colorWithRed:127/255.0 green:140/255.0 blue:141/255.0 alpha:1]; _buttonDestructiveBgColor = [UIColor colorWithRed:231/255.0 green:76/255.0 blue:60/255.0 alpha:1]; - _textFeildHeight = kTextFeildHeight; - _textFeildEdge = kTextFeildEdge; - _textFeildorderWidth = KTextFeildBorderWidth; - _textFeildContentViewEdge = kContentViewEdge; + _textFieldHeight = kTextFieldHeight; + _textFieldEdge = kTextFieldEdge; + _textFieldBorderWidth = KTextFieldBorderWidth; + _textFieldContentViewEdge = kContentViewEdge; _textFieldBorderColor = [UIColor colorWithRed:203/255.0 green:203/255.0 blue:203/255.0 alpha:1]; _textFieldBackgroudColor = [UIColor whiteColor]; @@ -154,8 +156,8 @@ - (UIColor *)buttonBgColorWithStyle:(TYAlertActionStyle)style switch (style) { case TYAlertActionStyleDefault: return _buttonDefaultBgColor; - case TYAlertActionStyleCancle: - return _buttonCancleBgColor; + case TYAlertActionStyleCancel: + return _buttonCancelBgColor; case TYAlertActionStyleDestructive: return _buttonDestructiveBgColor; @@ -172,9 +174,9 @@ - (void)addContentViews [self addSubview:textContentView]; _textContentView = textContentView; - UIView *textFeildContentView = [[UIView alloc]init]; - [self addSubview:textFeildContentView]; - _textFeildContentView = textFeildContentView; + UIView *textFieldContentView = [[UIView alloc]init]; + [self addSubview:textFieldContentView]; + _textFieldContentView = textFieldContentView; UIView *buttonContentView = [[UIView alloc]init]; buttonContentView.userInteractionEnabled = YES; @@ -233,14 +235,14 @@ - (void)addAction:(TYAlertAction *)action [self layoutButtons]; } -- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textFeild))configurationHandler +- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler { - if (_textFeilds == nil) { - _textFeilds = [NSMutableArray array]; + if (_textFields == nil) { + _textFields = [NSMutableArray array]; } UITextField *textField = [[UITextField alloc]init]; - textField.tag = kTextFeildOffset + _textFeilds.count; + textField.tag = kTextFieldOffset + _textFields.count; textField.font = _textFieldFont; textField.translatesAutoresizingMaskIntoConstraints = NO; @@ -248,26 +250,26 @@ - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textFeild))c configurationHandler(textField); } - [_textFeildContentView addSubview:textField]; - [_textFeilds addObject:textField]; + [_textFieldContentView addSubview:textField]; + [_textFields addObject:textField]; - if (_textFeilds.count > 1) { - if (_textFeildSeparateViews == nil) { - _textFeildSeparateViews = [NSMutableArray array]; + if (_textFields.count > 1) { + if (_textFieldSeparateViews == nil) { + _textFieldSeparateViews = [NSMutableArray array]; } UIView *separateView = [[UIView alloc]init]; separateView.backgroundColor = _textFieldBorderColor; separateView.translatesAutoresizingMaskIntoConstraints = NO; - [_textFeildContentView addSubview:separateView]; - [_textFeildSeparateViews addObject:separateView]; + [_textFieldContentView addSubview:separateView]; + [_textFieldSeparateViews addObject:separateView]; } - [self layoutTextFeilds]; + [self layoutTextFields]; } - (NSArray *)textFieldArray { - return _textFeilds; + return _textFields; } #pragma mark - layout contenview @@ -279,26 +281,26 @@ - (void)layoutContentViews return; } if (_alertViewWidth) { - [self addConstarintWidth:_alertViewWidth height:0]; + [self addConstraintWidth:_alertViewWidth height:0]; } // textContentView _textContentView.translatesAutoresizingMaskIntoConstraints = NO; - [self addConstarintWithView:_textContentView topView:self leftView:self bottomView:nil rightView:self edageInset:UIEdgeInsetsMake(_contentViewSpace, _textLabelContentViewEdge, 0, -_textLabelContentViewEdge)]; + [self addConstraintWithView:_textContentView topView:self leftView:self bottomView:nil rightView:self edgeInset:UIEdgeInsetsMake(_contentViewSpace, _textLabelContentViewEdge, 0, -_textLabelContentViewEdge)]; - // textFeildContentView - _textFeildContentView.translatesAutoresizingMaskIntoConstraints = NO; - _textFeildTopConstraint = [self addConstarintWithTopView:_textContentView toBottomView:_textFeildContentView constarint:0]; + // textFieldContentView + _textFieldContentView.translatesAutoresizingMaskIntoConstraints = NO; + _textFieldTopConstraint = [self addConstraintWithTopView:_textContentView toBottomView:_textFieldContentView constant:0]; - [self addConstarintWithView:_textFeildContentView topView:nil leftView:self bottomView:nil rightView:self edageInset:UIEdgeInsetsMake(0, _textFeildContentViewEdge, 0, -_textFeildContentViewEdge)]; + [self addConstraintWithView:_textFieldContentView topView:nil leftView:self bottomView:nil rightView:self edgeInset:UIEdgeInsetsMake(0, _textFieldContentViewEdge, 0, -_textFieldContentViewEdge)]; // buttonContentView _buttonContentView.translatesAutoresizingMaskIntoConstraints = NO; - _buttonTopConstraint = [self addConstarintWithTopView:_textFeildContentView toBottomView:_buttonContentView constarint:0]; + _buttonTopConstraint = [self addConstraintWithTopView:_textFieldContentView toBottomView:_buttonContentView constant:_buttonContentViewTop]; - [self addConstarintWithView:_buttonContentView topView:nil leftView:self bottomView:self rightView:self edageInset:UIEdgeInsetsMake(0, _buttonContentViewEdge, -_contentViewSpace, -_buttonContentViewEdge)]; + [self addConstraintWithView:_buttonContentView topView:nil leftView:self bottomView:self rightView:self edgeInset:UIEdgeInsetsMake(0, _buttonContentViewEdge, -_contentViewSpace, -_buttonContentViewEdge)]; } - (void)layoutTextLabels @@ -309,74 +311,74 @@ - (void)layoutTextLabels } // title _titleLable.translatesAutoresizingMaskIntoConstraints = NO; - [_textContentView addConstarintWithView:_titleLable topView:_textContentView leftView:_textContentView bottomView:nil rightView:_textContentView edageInset:UIEdgeInsetsZero]; + [_textContentView addConstraintWithView:_titleLable topView:_textContentView leftView:_textContentView bottomView:nil rightView:_textContentView edgeInset:UIEdgeInsetsZero]; // message _messageLabel.translatesAutoresizingMaskIntoConstraints = NO; - [_textContentView addConstarintWithTopView:_titleLable toBottomView:_messageLabel constarint:_textLabelSpace]; - [_textContentView addConstarintWithView:_messageLabel topView:nil leftView:_textContentView bottomView:_textContentView rightView:_textContentView edageInset:UIEdgeInsetsZero]; + [_textContentView addConstraintWithTopView:_titleLable toBottomView:_messageLabel constant:_textLabelSpace]; + [_textContentView addConstraintWithView:_messageLabel topView:nil leftView:_textContentView bottomView:_textContentView rightView:_textContentView edgeInset:UIEdgeInsetsZero]; } - (void)layoutButtons { UIButton *button = _buttons.lastObject; if (_buttons.count == 1) { - _buttonTopConstraint.constant = -_contentViewSpace; - [_buttonContentView addConstraintToView:button edageInset:UIEdgeInsetsZero]; - [button addConstarintWidth:0 height:_buttonHeight]; + _buttonTopConstraint.constant = -_buttonContentViewTop; + [_buttonContentView addConstraintToView:button edgeInset:UIEdgeInsetsZero]; + [button addConstraintWidth:0 height:_buttonHeight]; }else if (_buttons.count == 2) { UIButton *firstButton = _buttons.firstObject; - [_buttonContentView removeConstraintWithView:firstButton attribte:NSLayoutAttributeRight]; - [_buttonContentView addConstarintWithView:button topView:_buttonContentView leftView:nil bottomView:nil rightView:_buttonContentView edageInset:UIEdgeInsetsZero]; - [_buttonContentView addConstarintWithLeftView:firstButton toRightView:button constarint:_buttonSpace]; - [_buttonContentView addConstarintEqualWithView:button widthToView:firstButton heightToView:firstButton]; + [_buttonContentView removeConstraintWithView:firstButton attribute:NSLayoutAttributeRight]; + [_buttonContentView addConstraintWithView:button topView:_buttonContentView leftView:nil bottomView:nil rightView:_buttonContentView edgeInset:UIEdgeInsetsZero]; + [_buttonContentView addConstraintWithLeftView:firstButton toRightView:button constant:_buttonSpace]; + [_buttonContentView addConstraintEqualWithView:button widthToView:firstButton heightToView:firstButton]; }else { if (_buttons.count == 3) { UIButton *firstBtn = _buttons[0]; UIButton *secondBtn = _buttons[1]; - [_buttonContentView removeConstraintWithView:firstBtn attribte:NSLayoutAttributeRight]; - [_buttonContentView removeConstraintWithView:firstBtn attribte:NSLayoutAttributeBottom]; - [_buttonContentView removeConstraintWithView:secondBtn attribte:NSLayoutAttributeTop]; - [_buttonContentView addConstarintWithView:firstBtn topView:nil leftView:nil bottomView:0 rightView:_buttonContentView edageInset:UIEdgeInsetsZero]; - [_buttonContentView addConstarintWithTopView:firstBtn toBottomView:secondBtn constarint:_buttonSpace]; + [_buttonContentView removeConstraintWithView:firstBtn attribute:NSLayoutAttributeRight]; + [_buttonContentView removeConstraintWithView:firstBtn attribute:NSLayoutAttributeBottom]; + [_buttonContentView removeConstraintWithView:secondBtn attribute:NSLayoutAttributeTop]; + [_buttonContentView addConstraintWithView:firstBtn topView:nil leftView:nil bottomView:nil rightView:_buttonContentView edgeInset:UIEdgeInsetsZero]; + [_buttonContentView addConstraintWithTopView:firstBtn toBottomView:secondBtn constant:_buttonSpace]; } - UIButton *lastSecondBtn = _buttons[_buttons.count-2]; - [_buttonContentView removeConstraintWithView:lastSecondBtn attribte:NSLayoutAttributeBottom]; - [_buttonContentView addConstarintWithTopView:lastSecondBtn toBottomView:button constarint:_buttonSpace]; - [_buttonContentView addConstarintWithView:button topView:nil leftView:_buttonContentView bottomView:_buttonContentView rightView:_buttonContentView edageInset:UIEdgeInsetsZero]; - [_buttonContentView addConstarintEqualWithView:button widthToView:nil heightToView:lastSecondBtn]; + UIButton *lastSecondBtn = _buttons[_buttons.count - 2]; + [_buttonContentView removeConstraintWithView:lastSecondBtn attribute:NSLayoutAttributeBottom]; + [_buttonContentView addConstraintWithTopView:lastSecondBtn toBottomView:button constant:_buttonSpace]; + [_buttonContentView addConstraintWithView:button topView:nil leftView:_buttonContentView bottomView:_buttonContentView rightView:_buttonContentView edgeInset:UIEdgeInsetsZero]; + [_buttonContentView addConstraintEqualWithView:button widthToView:nil heightToView:lastSecondBtn]; } } -- (void)layoutTextFeilds +- (void)layoutTextFields { - UITextField *textFeild = _textFeilds.lastObject; + UITextField *textField = _textFields.lastObject; - if (_textFeilds.count == 1) { - // setup textFeildContentView - _textFeildContentView.backgroundColor = _textFieldBackgroudColor; - _textFeildContentView.layer.masksToBounds = YES; - _textFeildContentView.layer.cornerRadius = 4; - _textFeildContentView.layer.borderWidth = _textFeildorderWidth; - _textFeildContentView.layer.borderColor = _textFieldBorderColor.CGColor; - _textFeildTopConstraint.constant = -_contentViewSpace; - [_textFeildContentView addConstraintToView:textFeild edageInset:UIEdgeInsetsMake(_textFeildorderWidth, _textFeildEdge, -_textFeildorderWidth, -_textFeildEdge)]; - [textFeild addConstarintWidth:0 height:_textFeildHeight]; + if (_textFields.count == 1) { + // setup textFieldContentView + _textFieldContentView.backgroundColor = _textFieldBackgroudColor; + _textFieldContentView.layer.masksToBounds = YES; + _textFieldContentView.layer.cornerRadius = 4; + _textFieldContentView.layer.borderWidth = _textFieldBorderWidth; + _textFieldContentView.layer.borderColor = _textFieldBorderColor.CGColor; + _textFieldTopConstraint.constant = -_contentViewSpace; + [_textFieldContentView addConstraintToView:textField edgeInset:UIEdgeInsetsMake(_textFieldBorderWidth, _textFieldEdge, -_textFieldBorderWidth, -_textFieldEdge)]; + [textField addConstraintWidth:0 height:_textFieldHeight]; }else { - // textFeild - UITextField *lastSecondTextFeild = _textFeilds[_textFeilds.count - 2]; - [_textFeildContentView removeConstraintWithView:lastSecondTextFeild attribte:NSLayoutAttributeBottom]; - [_textFeildContentView addConstarintWithTopView:lastSecondTextFeild toBottomView:textFeild constarint:_textFeildorderWidth]; - [_textFeildContentView addConstarintWithView:textFeild topView:nil leftView:_textFeildContentView bottomView:_textFeildContentView rightView:_textFeildContentView edageInset:UIEdgeInsetsMake(0, _textFeildEdge, -_textFeildorderWidth, -_textFeildEdge)]; - [_textFeildContentView addConstarintEqualWithView:textFeild widthToView:nil heightToView:lastSecondTextFeild]; + // textField + UITextField *lastSecondTextField = _textFields[_textFields.count - 2]; + [_textFieldContentView removeConstraintWithView:lastSecondTextField attribute:NSLayoutAttributeBottom]; + [_textFieldContentView addConstraintWithTopView:lastSecondTextField toBottomView:textField constant:_textFieldBorderWidth]; + [_textFieldContentView addConstraintWithView:textField topView:nil leftView:_textFieldContentView bottomView:_textFieldContentView rightView:_textFieldContentView edgeInset:UIEdgeInsetsMake(0, _textFieldEdge, -_textFieldBorderWidth, -_textFieldEdge)]; + [_textFieldContentView addConstraintEqualWithView:textField widthToView:nil heightToView:lastSecondTextField]; // separateview - UIView *separateView = _textFeildSeparateViews[_textFeilds.count - 2]; - [_textFeildContentView addConstarintWithView:separateView topView:nil leftView:_textFeildContentView bottomView:nil rightView:_textFeildContentView edageInset:UIEdgeInsetsZero]; - [_textFeildContentView addConstarintWithTopView:separateView toBottomView:textFeild constarint:0]; - [separateView addConstarintWidth:0 height:_textFeildorderWidth]; + UIView *separateView = _textFieldSeparateViews[_textFields.count - 2]; + [_textFieldContentView addConstraintWithView:separateView topView:nil leftView:_textFieldContentView bottomView:nil rightView:_textFieldContentView edgeInset:UIEdgeInsetsZero]; + [_textFieldContentView addConstraintWithTopView:separateView toBottomView:textField constant:0]; + [separateView addConstraintWidth:0 height:_textFieldBorderWidth]; } } @@ -386,16 +388,18 @@ - (void)actionButtonClicked:(UIButton *)button { TYAlertAction *action = _actions[button.tag - kButtonTagOffset]; - [self hideView]; + if (_clickedAutoHide) { + [self hideView]; + } if (action.handler) { action.handler(action); } } -- (void)dealloc -{ - NSLog(@"%@ dealloc",NSStringFromClass([self class])); -} +//- (void)dealloc +//{ +// NSLog(@"%@ dealloc",NSStringFromClass([self class])); +//} @end diff --git a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h index ba23388..11e185e 100644 --- a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h +++ b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.h @@ -17,7 +17,6 @@ @property (nonatomic, assign) CGFloat alertViewOriginY; // default center Y @property (nonatomic, assign) CGFloat alertViewEdging; // default 15 - +(void)showAlertViewWithView:(UIView *)alertView; + (void)showAlertViewWithView:(UIView *)alertView backgoundTapDismissEnable:(BOOL)backgoundTapDismissEnable; diff --git a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m index 92214af..98989c1 100644 --- a/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m +++ b/TYAlertControllerDemo/TYAlertController/TYShowAlertView.m @@ -15,7 +15,7 @@ @interface TYShowAlertView () @end //current window -#define kCurrentWindow [[UIApplication sharedApplication].windows firstObject] +#define kCurrentWindow [UIApplication sharedApplication].keyWindow @implementation TYShowAlertView @@ -84,7 +84,7 @@ - (void)addBackgroundView } [self insertSubview:_backgroundView atIndex:0]; _backgroundView.translatesAutoresizingMaskIntoConstraints = NO; - [self addConstraintToView:_backgroundView edageInset:UIEdgeInsetsZero]; + [self addConstraintToView:_backgroundView edgeInset:UIEdgeInsetsZero]; } - (void)setBackgroundView:(UIView *)backgroundView @@ -106,7 +106,7 @@ - (void)didMoveToSuperview { if (self.superview) { self.translatesAutoresizingMaskIntoConstraints = NO; - [self.superview addConstraintToView:self edageInset:UIEdgeInsetsZero]; + [self.superview addConstraintToView:self edgeInset:UIEdgeInsetsZero]; [self layoutAlertView]; } } @@ -115,11 +115,11 @@ - (void)layoutAlertView { _alertView.translatesAutoresizingMaskIntoConstraints = NO; // center X - [self addConstraintCenterXToView:_alertView CenterYToView:nil]; + [self addConstraintCenterXToView:_alertView centerYToView:nil]; // width, height if (!CGSizeEqualToSize(_alertView.frame.size,CGSizeZero)) { - [_alertView addConstarintWidth:CGRectGetWidth(_alertView.frame) height:CGRectGetHeight(_alertView.frame)]; + [_alertView addConstraintWidth:CGRectGetWidth(_alertView.frame) height:CGRectGetHeight(_alertView.frame)]; }else { BOOL findAlertViewWidthConstraint = NO; @@ -131,7 +131,7 @@ - (void)layoutAlertView } if (!findAlertViewWidthConstraint) { - [_alertView addConstarintWidth:CGRectGetWidth(self.superview.frame)-2*_alertViewEdging height:0]; + [_alertView addConstraintWidth:CGRectGetWidth(self.superview.frame)-2*_alertViewEdging height:0]; } } diff --git a/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.h b/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.h index fbe74f8..0551f61 100644 --- a/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.h +++ b/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.h @@ -10,26 +10,26 @@ @interface UIView (TYAutoLayout) -- (void)addConstraintToView:(UIView *)view edageInset:(UIEdgeInsets)edageInset; +- (void)addConstraintToView:(UIView *)view edgeInset:(UIEdgeInsets)edgeInset; -- (void)addConstarintWithView:(UIView *)view topView:(UIView *)topView leftView:(UIView *)leftView - bottomView:(UIView *)bottomView rightView:(UIView *)rightView edageInset:(UIEdgeInsets)edageInset; +- (void)addConstraintWithView:(UIView *)view topView:(UIView *)topView leftView:(UIView *)leftView + bottomView:(UIView *)bottomView rightView:(UIView *)rightView edgeInset:(UIEdgeInsets)edgeInset; -- (void)addConstarintWithLeftView:(UIView *)leftView toRightView:(UIView *)rightView constarint:(CGFloat)constarint; +- (void)addConstraintWithLeftView:(UIView *)leftView toRightView:(UIView *)rightView constant:(CGFloat)constant; -- (NSLayoutConstraint *)addConstarintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constarint:(CGFloat)constarint; +- (NSLayoutConstraint *)addConstraintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constant:(CGFloat)constant; -- (void)addConstarintWidth:(CGFloat)width height:(CGFloat)height; +- (void)addConstraintWidth:(CGFloat)width height:(CGFloat)height; -- (void)addConstarintEqualWithView:(UIView *)view widthToView:(UIView *)wView heightToView:(UIView *)hView; +- (void)addConstraintEqualWithView:(UIView *)view widthToView:(UIView *)wView heightToView:(UIView *)hView; - (NSLayoutConstraint *)addConstraintCenterYToView:(UIView *)yView constant:(CGFloat)constant; -- (void)addConstraintCenterXToView:(UIView *)xView CenterYToView:(UIView *)yView; +- (void)addConstraintCenterXToView:(UIView *)xView centerYToView:(UIView *)yView; - (void)removeConstraintWithAttribte:(NSLayoutAttribute)attr; -- (void)removeConstraintWithView:(UIView *)view attribte:(NSLayoutAttribute)attr; +- (void)removeConstraintWithView:(UIView *)view attribute:(NSLayoutAttribute)attr; - (void)removeAllConstraints; diff --git a/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.m b/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.m index 329125b..e0c0316 100644 --- a/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.m +++ b/TYAlertControllerDemo/TYAlertController/UIView+TYAutoLayout.m @@ -10,44 +10,44 @@ @implementation UIView (TYAutoLayout) -- (void)addConstraintToView:(UIView *)view edageInset:(UIEdgeInsets)edageInset +- (void)addConstraintToView:(UIView *)view edgeInset:(UIEdgeInsets)edgeInset { - [self addConstarintWithView:view topView:self leftView:self bottomView:self rightView:self edageInset:edageInset]; + [self addConstraintWithView:view topView:self leftView:self bottomView:self rightView:self edgeInset:edgeInset]; } -- (void)addConstarintWithView:(UIView *)view topView:(UIView *)topView leftView:(UIView *)leftView - bottomView:(UIView *)bottomView rightView:(UIView *)rightView edageInset:(UIEdgeInsets)edageInset +- (void)addConstraintWithView:(UIView *)view topView:(UIView *)topView leftView:(UIView *)leftView + bottomView:(UIView *)bottomView rightView:(UIView *)rightView edgeInset:(UIEdgeInsets)edgeInset { if (topView) { - [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:topView attribute:NSLayoutAttributeTop multiplier:1 constant:edageInset.top]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:topView attribute:NSLayoutAttributeTop multiplier:1 constant:edgeInset.top]]; } if (leftView) { - [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:leftView attribute:NSLayoutAttributeLeft multiplier:1 constant:edageInset.left]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:leftView attribute:NSLayoutAttributeLeft multiplier:1 constant:edgeInset.left]]; } if (rightView) { - [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:rightView attribute:NSLayoutAttributeRight multiplier:1 constant:edageInset.right]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:rightView attribute:NSLayoutAttributeRight multiplier:1 constant:edgeInset.right]]; } if (bottomView) { - [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeBottom multiplier:1 constant:edageInset.bottom]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeBottom multiplier:1 constant:edgeInset.bottom]]; } } -- (void)addConstarintWithLeftView:(UIView *)leftView toRightView:(UIView *)rightView constarint:(CGFloat)constarint +- (void)addConstraintWithLeftView:(UIView *)leftView toRightView:(UIView *)rightView constant:(CGFloat)constant { - [self addConstraint:[NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:rightView attribute:NSLayoutAttributeLeft multiplier:1 constant:-constarint]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:rightView attribute:NSLayoutAttributeLeft multiplier:1 constant:-constant]]; } -- (NSLayoutConstraint *)addConstarintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constarint:(CGFloat)constarint +- (NSLayoutConstraint *)addConstraintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constant:(CGFloat)constant { - NSLayoutConstraint *topButtomConstraint =[NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeTop multiplier:1 constant:-constarint]; - [self addConstraint:topButtomConstraint]; - return topButtomConstraint; + NSLayoutConstraint *topBottomConstraint =[NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeTop multiplier:1 constant:-constant]; + [self addConstraint:topBottomConstraint]; + return topBottomConstraint; } -- (void)addConstarintWidth:(CGFloat)width height:(CGFloat)height +- (void)addConstraintWidth:(CGFloat)width height:(CGFloat)height { if (width > 0) { [self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:width]]; @@ -58,7 +58,7 @@ - (void)addConstarintWidth:(CGFloat)width height:(CGFloat)height } } -- (void)addConstarintEqualWithView:(UIView *)view widthToView:(UIView *)wView heightToView:(UIView *)hView +- (void)addConstraintEqualWithView:(UIView *)view widthToView:(UIView *)wView heightToView:(UIView *)hView { if (wView) { [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:wView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]]; @@ -69,7 +69,7 @@ - (void)addConstarintEqualWithView:(UIView *)view widthToView:(UIView *)wView he } } -- (void)addConstraintCenterXToView:(UIView *)xView CenterYToView:(UIView *)yView +- (void)addConstraintCenterXToView:(UIView *)xView centerYToView:(UIView *)yView { if (xView) { [self addConstraint:[NSLayoutConstraint constraintWithItem:xView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]]; @@ -100,7 +100,7 @@ - (void)removeConstraintWithAttribte:(NSLayoutAttribute)attr } } -- (void)removeConstraintWithView:(UIView *)view attribte:(NSLayoutAttribute)attr +- (void)removeConstraintWithView:(UIView *)view attribute:(NSLayoutAttribute)attr { for (NSLayoutConstraint *constraint in self.constraints) { if (constraint.firstAttribute == attr && constraint.firstItem == view) { diff --git a/TYAlertControllerDemo/ViewController.m b/TYAlertControllerDemo/ViewController.m index ebb35a1..39182f6 100644 --- a/TYAlertControllerDemo/ViewController.m +++ b/TYAlertControllerDemo/ViewController.m @@ -23,6 +23,7 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. + } @@ -30,7 +31,7 @@ - (IBAction)showAlertViewAction:(id)sender { TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt text and textfiled. "]; - [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) { + [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) { NSLog(@"%@",action.title); }]]; @@ -53,6 +54,27 @@ - (IBAction)showAlertViewAction:(id)sender { // first way to show TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert]; + + [alertController setViewWillShowHandler:^(UIView *alertView) { + NSLog(@"ViewWillShow"); + }]; + + [alertController setViewDidShowHandler:^(UIView *alertView) { + NSLog(@"ViewDidShow"); + }]; + + [alertController setViewWillHideHandler:^(UIView *alertView) { + NSLog(@"ViewWillHide"); + }]; + + [alertController setViewDidHideHandler:^(UIView *alertView) { + NSLog(@"ViewDidHide"); + }]; + + [alertController setDismissComplete:^{ + NSLog(@"DismissComplete"); + }]; + //alertController.alertViewOriginY = 60; [self presentViewController:alertController animated:YES completion:nil]; @@ -75,7 +97,7 @@ - (IBAction)showActionSheetAction:(id)sender { [alertView addAction:[TYAlertAction actionWithTitle:@"删除" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) { NSLog(@"%@",action.title); }]]; - [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) { + [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) { NSLog(@"%@",action.title); }]]; @@ -98,7 +120,7 @@ - (IBAction)blurEffectAlertViewAction:(id)sender { - (IBAction)dropdwonAnimationAction:(id)sender { TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt dropdwon animation. "]; - [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) { + [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) { NSLog(@"%@",action.title); }]]; @@ -127,7 +149,7 @@ - (IBAction)showAlertViewInWindowAction:(id)sender { TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"A message should be a short, but it can support long message, hahahhahahahahhahahahahhaahahhahahahahahhahahahahhahahahahahhahahahahahhahahahhahahhahahahahh. (NSTextAlignmentCenter)"]; - [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) { + [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) { }]];