diff --git a/LMAlertView.podspec b/LMAlertView.podspec index 21da812..4ff569c 100644 --- a/LMAlertView.podspec +++ b/LMAlertView.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = 'LMAlertView' - s.version = '1.1.0' + s.version = '1.1.1' s.license = 'MIT' s.summary = 'Open Source, customisable clone of UIAlertView for iOS 7' - s.homepage = 'https://github.com/lmcd/LMAlertView' + s.homepage = 'https://github.com/Azat92/LMAlertView' s.authors = { 'Lee McDermott' => 'lmalertview@leemcdermott.co.uk' } - s.source = { :git => 'https://github.com/lmcd/LMAlertView.git', :tag => 'v1.1.0' } + s.source = { :git => 'https://github.com/Azat92/LMAlertView.git', :tag => 'v1.1.1' } s.requires_arc = true s.ios.deployment_target = '7.0' diff --git a/LMAlertView/CALayer+ModalAlert.m b/LMAlertView/CALayer+ModalAlert.m index 085311c..2ccf925 100644 --- a/LMAlertView/CALayer+ModalAlert.m +++ b/LMAlertView/CALayer+ModalAlert.m @@ -23,26 +23,11 @@ + (void)load method_exchangeImplementations(originalMethod, overrideMethod); } -- (UIWindow *)windowForView:(UIView *)view -{ - UIView *tempView = view; - - while (tempView.superview != nil) { - tempView = tempView.superview; - - if ([tempView isKindOfClass:[UIWindow class]]) { - return (UIWindow *)tempView; - } - } - - return nil; -} - - (void)_addAnimation:(CAAnimation *)anim forKey:(NSString *)key { - UIView *view = [self delegate]; - UIWindow *window = [self windowForView:view]; + UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; - if ([window.rootViewController isKindOfClass:[LMEmbeddedViewController class]]) { + if ([keyWindow.rootViewController isKindOfClass:[LMEmbeddedViewController class]]) { + UIView *view = [self delegate]; CABasicAnimation *basicAnim = (CABasicAnimation *)anim; CGFloat modalWidth = 290.0; diff --git a/LMAlertView/LMAlertView.h b/LMAlertView/LMAlertView.h index 84ead9d..6698b9b 100644 --- a/LMAlertView/LMAlertView.h +++ b/LMAlertView/LMAlertView.h @@ -24,11 +24,10 @@ - (float)velocity; @end #else -#import +#import "RBBSpringAnimation.h" #define kSpringAnimationClassName RBBSpringAnimation #endif - @interface LMAlertView : UIView @property (nonatomic, strong) UIColor *tintColor; @@ -43,7 +42,6 @@ @property(nonatomic, copy) NSString *title; @property(nonatomic, readonly, getter=isVisible) BOOL visible; @property(nonatomic) BOOL buttonsShouldStack; -@property(nonatomic) BOOL autoRotate; - (id)initWithSize:(CGSize)size; - (id)initWithViewController:(UIViewController *)viewController; @@ -55,8 +53,6 @@ - (void)show; - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated; -- (NSInteger)addButtonWithTitle:(NSString *)title; -- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex; - (LMModalItemTableViewCell *)buttonCellForIndex:(NSInteger)buttonIndex; diff --git a/LMAlertView/LMAlertView.m b/LMAlertView/LMAlertView.m index 2ad40d3..ed04aa7 100644 --- a/LMAlertView/LMAlertView.m +++ b/LMAlertView/LMAlertView.m @@ -9,7 +9,7 @@ #import "LMAlertView.h" #import "LMEmbeddedViewController.h" #import "LMModalItemTableViewCell.h" -#import +#import "CAAnimation+Blocks.h" @interface LMAlertView () @@ -21,7 +21,6 @@ @interface LMAlertView () @property (nonatomic, strong, readonly) UIToolbar *toolbar; -@property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *messageLabel; @property (nonatomic, strong) UITableView *buttonTableView; @@ -33,8 +32,6 @@ @interface LMAlertView () @property (nonatomic, copy) NSString *cancelButtonTitle; @property (nonatomic, strong) NSMutableArray *otherButtonsTitles; -- (void)setupWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles; - @end @implementation LMAlertView @@ -75,17 +72,44 @@ - (id)initWithViewController:(UIViewController *)viewController [self.contentView addSubview:destinationViewController.view]; self.contentView.autoresizesSubviews = NO; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil]; } return self; } +BOOL systemVersionGOE(NSString *v) { + return ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending); +} + +BOOL systemVersionL(NSString *v) { + return ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending); +} + +BOOL iOS7() { + return systemVersionGOE(@"7.0") && systemVersionL(@"8.0"); +} + - (void)keyboardWillShow:(NSNotification *)notification { - CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; + CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; self.representationView.layer.anchorPoint = CGPointMake(0.5, 0.5); - self.representationView.center = CGPointMake([[UIScreen mainScreen] bounds].size.width / 2.0, ([[UIScreen mainScreen] bounds].size.height - keyboardSize.height) / 2.0); + CGRect bounds = [[UIScreen mainScreen] bounds]; + CGFloat boundsWidth = bounds.size.width; + CGFloat boundsHeight = bounds.size.height; + CGFloat keyboardHeight = keyboardSize.height; + + if (iOS7()) { + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + CGFloat boundsWidthBackup = boundsWidth; + boundsWidth = UIInterfaceOrientationIsPortrait(orientation) ? boundsWidth : boundsHeight; + boundsHeight = UIInterfaceOrientationIsPortrait(orientation) ? boundsHeight : boundsWidthBackup; + keyboardHeight = UIInterfaceOrientationIsPortrait(orientation) ? keyboardHeight : keyboardSize.width; + } + + [UIView animateWithDuration:.3 animations:^{ + self.representationView.center = CGPointMake(boundsWidth / 2.0, (boundsHeight - keyboardHeight) / 2.0); + }]; } - (UITableView *)tableViewWithFrame:(CGRect)frame @@ -121,147 +145,153 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)d { self = [super init]; if (self) { - _delegate = delegate; - NSMutableArray *newOtherButtonTitles; - if (otherButtonTitles != nil) { - va_list args; - va_start(args, otherButtonTitles); - newOtherButtonTitles = [[NSMutableArray alloc] initWithObjects:otherButtonTitles, nil]; - id obj; - while ((obj = va_arg(args, id)) != nil) { - [newOtherButtonTitles addObject:obj]; - } - va_end(args); + _cancelButtonIndex = -1; + _firstOtherButtonIndex = -1; + + _delegate = delegate; + + if (otherButtonTitles != nil) { + va_list args; + va_start(args, otherButtonTitles); + _otherButtonsTitles = [[NSMutableArray alloc] initWithObjects:otherButtonTitles, nil]; + id obj; + while ((obj = va_arg(args, id)) != nil) { + [_otherButtonsTitles addObject:obj]; + } + va_end(args); + + _firstOtherButtonIndex = 1; + } + + _numberOfButtons = [_otherButtonsTitles count]; + + if (cancelButtonTitle != nil) { + _numberOfButtons++; + _cancelButtonIndex = 0; + _cancelButtonTitle = cancelButtonTitle; + } + + CGFloat sideMargin = 15.0; + CGFloat topBottomMargin = 19.0; + CGFloat alertWidth = 270.0; + CGFloat buttonHeight = 44.0; + CGFloat labelWidth = alertWidth - (sideMargin * 2.0); + + UIFont *titleFont = [UIFont boldSystemFontOfSize:17.0]; + + CGFloat yOffset = topBottomMargin; + + UILabel *titleLabel; + UIView *lineView; + + if (title != nil) { + self.title = title; + + // The UILabels in UIAlertView mysteriously have no paragraph style but STILL have line heights + // I suspect there's some UILabel private API fuckery afoot + NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init]; + //[paragrahStyle setLineSpacing:2]; + + NSDictionary *attributes = @{ + NSParagraphStyleAttributeName: paragrahStyle, + NSFontAttributeName: titleFont + }; + + titleLabel = [[UILabel alloc] init]; + titleLabel.attributedText = [[NSAttributedString alloc] initWithString:title attributes:attributes]; + titleLabel.numberOfLines = 0; + titleLabel.textAlignment = NSTextAlignmentCenter; + + CGSize sizeThatFits = [titleLabel sizeThatFits:CGSizeMake(labelWidth, MAXFLOAT)]; + titleLabel.frame = CGRectMake(sideMargin, yOffset, labelWidth, sizeThatFits.height); + + yOffset += titleLabel.frame.size.height; + } + + // 4px gap between title and message + // Even if a title doesn't exist, the 4px is still present + yOffset += 4.0; + + if (message != nil) { + self.messageLabel = [[UILabel alloc] init]; + self.messageLabel.numberOfLines = 0; + self.message = message; + + CGSize sizeThatFits = [self.messageLabel sizeThatFits:CGSizeMake(labelWidth, MAXFLOAT)]; + self.messageLabel.frame = CGRectMake(sideMargin, yOffset, labelWidth, sizeThatFits.height); + + yOffset += self.messageLabel.frame.size.height; + } + + yOffset += topBottomMargin; + + // Lines setup + if (self.numberOfButtons > 0) { + lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, yOffset - 1.0, alertWidth, 1.0)]; + lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; + + // We put our 0.5px high view in to a container that's 1px high + // This is because autoresizing was rounding up to 1 and messing things up + // autolayout might fix this + UIView *lineViewInner = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.5, alertWidth, 0.5)]; + lineViewInner.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]; + lineViewInner.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + [lineView addSubview:lineViewInner]; } + + BOOL sideBySideButtons = (self.numberOfButtons == 2); + BOOL buttonsShouldStack = !sideBySideButtons; + + if (sideBySideButtons) { + CGFloat halfWidth = (alertWidth / 2.0); + + UIView *lineVerticalViewInner = [[UIView alloc] initWithFrame:CGRectMake(halfWidth, 0.5, 0.5, buttonHeight + 0.5)]; + lineVerticalViewInner.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]; + [lineView addSubview:lineVerticalViewInner]; + + _buttonTableView = [self tableViewWithFrame:CGRectMake(0.0, yOffset, halfWidth, buttonHeight)]; + _otherTableView = [self tableViewWithFrame:CGRectMake(halfWidth, yOffset, halfWidth, buttonHeight)]; + + yOffset += buttonHeight; + } + else { + NSInteger numberOfOtherButtons = [self.otherButtonsTitles count]; + + if (numberOfOtherButtons > 0) { + CGFloat tableHeight = buttonsShouldStack ? numberOfOtherButtons * buttonHeight : buttonHeight; + + _buttonTableView = [self tableViewWithFrame:CGRectMake(0.0, yOffset, alertWidth, tableHeight)]; + + yOffset += tableHeight; + } + + if (cancelButtonTitle != nil) { + _otherTableView = [self tableViewWithFrame:CGRectMake(0.0, yOffset, alertWidth, buttonHeight)]; + + yOffset += buttonHeight; + } + } + + _buttonTableView.tag = 0; + _otherTableView.tag = 1; + + [_buttonTableView reloadData]; + [_otherTableView reloadData]; - [self setupWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitles:newOtherButtonTitles]; + CGFloat alertHeight = yOffset; + [self setupWithSize:CGSizeMake(alertWidth, alertHeight)]; + + // Add everything to the content view + [self.contentView addSubview:titleLabel]; + [self.contentView addSubview:self.messageLabel]; + [self.contentView addSubview:self.buttonTableView]; + [self.contentView addSubview:self.otherTableView]; + [self.contentView addSubview:lineView]; } return self; } -- (void)setupWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSArray *)otherButtonTitles; -{ - _cancelButtonIndex = -1; - _firstOtherButtonIndex = -1; - _cancelButtonTitle = nil; - if (otherButtonTitles != nil) { - _otherButtonsTitles = [[NSMutableArray alloc] initWithArray:otherButtonTitles]; - _firstOtherButtonIndex = 1; - } - - _numberOfButtons = [_otherButtonsTitles count]; - - if (cancelButtonTitle != nil) { - _numberOfButtons++; - _cancelButtonIndex = 0; - _cancelButtonTitle = cancelButtonTitle; - } - - CGFloat sideMargin = 15.0; - CGFloat topBottomMargin = 19.0; - CGFloat alertWidth = 270.0; - CGFloat buttonHeight = 44.0; - CGFloat labelWidth = alertWidth - (sideMargin * 2.0); - - CGFloat yOffset = topBottomMargin; - - UIView *lineView; - - if (title != nil) { - self.titleLabel = [[UILabel alloc] init]; - self.titleLabel.numberOfLines = 0; - self.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; - self.title = title; - - CGSize sizeThatFits = [self.titleLabel sizeThatFits:CGSizeMake(labelWidth, MAXFLOAT)]; - self.titleLabel.frame = CGRectMake(sideMargin, yOffset, labelWidth, sizeThatFits.height); - - yOffset += self.titleLabel.frame.size.height; - } - - // 4px gap between title and message - // Even if a title doesn't exist, the 4px is still present - yOffset += 4.0; - - if (message != nil) { - self.messageLabel = [[UILabel alloc] init]; - self.messageLabel.numberOfLines = 0; - self.messageLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth; - self.message = message; - - CGSize sizeThatFits = [self.messageLabel sizeThatFits:CGSizeMake(labelWidth, MAXFLOAT)]; - self.messageLabel.frame = CGRectMake(sideMargin, yOffset, labelWidth, sizeThatFits.height); - - yOffset += self.messageLabel.frame.size.height; - } - - yOffset += topBottomMargin; - - // Lines setup - if (self.numberOfButtons > 0) { - lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, yOffset - 1.0, alertWidth, 1.0)]; - lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - // We put our 0.5px high view in to a container that's 1px high - // This is because autoresizing was rounding up to 1 and messing things up - // autolayout might fix this - UIView *lineViewInner = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.5, alertWidth, 0.5)]; - lineViewInner.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]; - lineViewInner.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [lineView addSubview:lineViewInner]; - } - - BOOL sideBySideButtons = (self.numberOfButtons == 2); - BOOL buttonsShouldStack = !sideBySideButtons; - - if (sideBySideButtons) { - CGFloat halfWidth = (alertWidth / 2.0); - - UIView *lineVerticalViewInner = [[UIView alloc] initWithFrame:CGRectMake(halfWidth, 0.5, 0.5, buttonHeight + 0.5)]; - lineVerticalViewInner.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]; - [lineView addSubview:lineVerticalViewInner]; - - _buttonTableView = [self tableViewWithFrame:CGRectMake(0.0, yOffset, halfWidth, buttonHeight)]; - _otherTableView = [self tableViewWithFrame:CGRectMake(halfWidth, yOffset, halfWidth, buttonHeight)]; - - yOffset += buttonHeight; - } - else { - NSInteger numberOfOtherButtons = [self.otherButtonsTitles count]; - - if (numberOfOtherButtons > 0) { - CGFloat tableHeight = buttonsShouldStack ? numberOfOtherButtons * buttonHeight : buttonHeight; - - _buttonTableView = [self tableViewWithFrame:CGRectMake(0.0, yOffset, alertWidth, tableHeight)]; - - yOffset += tableHeight; - } - - if (cancelButtonTitle != nil) { - _otherTableView = [self tableViewWithFrame:CGRectMake(0.0, yOffset, alertWidth, buttonHeight)]; - - yOffset += buttonHeight; - } - } - - _buttonTableView.tag = 0; - _otherTableView.tag = 1; - - [_buttonTableView reloadData]; - [_otherTableView reloadData]; - - CGFloat alertHeight = yOffset; - [self setupWithSize:CGSizeMake(alertWidth, alertHeight)]; - - // Add everything to the content view - [self.contentView addSubview:self.titleLabel]; - [self.contentView addSubview:self.messageLabel]; - [self.contentView addSubview:self.buttonTableView]; - [self.contentView addSubview:self.otherTableView]; - [self.contentView addSubview:lineView]; -} - - (void)setSize:(CGSize)size animated:(BOOL)animated { if (!animated) { @@ -397,29 +427,6 @@ - (kSpringAnimationClassName *)springAnimationForKeyPath:(NSString *)keyPath return animation; } -- (void)transformAlertContainerViewForOrientation{ -#define DegreesToRadians(degrees) (degrees * M_PI / 180) - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - CGAffineTransform transform; - switch (orientation) { - case UIInterfaceOrientationLandscapeLeft: - transform = CGAffineTransformMakeRotation(-DegreesToRadians(90)); - break; - case UIInterfaceOrientationLandscapeRight: - transform = CGAffineTransformMakeRotation(DegreesToRadians(90)); - break; - case UIInterfaceOrientationPortraitUpsideDown: - transform = CGAffineTransformMakeRotation(DegreesToRadians(180)); - break; - case UIInterfaceOrientationPortrait: - default: - transform = CGAffineTransformMakeRotation(DegreesToRadians(0)); - break; - } - - [self.alertContainerView setTransform:transform]; -} - - (void)show { if ([self.delegate respondsToSelector:@selector(willPresentAlertView:)]) { @@ -442,8 +449,6 @@ - (void)show // Same window level as regular alert views (above main window and status bar) self.window.windowLevel = UIWindowLevelAlert; self.window.hidden = NO; - - [self transformAlertContainerViewForOrientation]; [self.window makeKeyAndVisible]; @@ -455,7 +460,9 @@ - (void)show viewController2.view = self.alertContainerView; // We fake "present" this view controller so it can be dismissed elswhere - [viewController presentViewController:viewController2 animated:NO completion:nil]; + viewController.controllerToShow = viewController2; +// [viewController presentViewController:viewController2 animated:NO completion:nil]; + [viewController2 addChildViewController:self.controller]; } @@ -490,7 +497,7 @@ - (void)show // Fade in the gray background [self.backgroundView.layer addAnimation:opacityAnimation forKey:@"opacity"]; - + // Fade in the modal // Would love to fade in all these things at once, but UIToolbar doesn't like it [self.toolbar.layer addAnimation:opacityAnimation forKey:@"opacity"]; @@ -502,7 +509,7 @@ - (void)show - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self - name:UIKeyboardWillShowNotification + name:UIKeyboardDidShowNotification object:nil]; } @@ -511,7 +518,7 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim if ([self.delegate respondsToSelector:@selector(alertView:willDismissWithButtonIndex:)]) { [self.delegate alertView:(UIAlertView *)self willDismissWithButtonIndex:buttonIndex]; } - + // Completion block void (^completion)(BOOL finished) = ^(BOOL finished){ // Temporary bugfix @@ -519,6 +526,8 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim // Release window from memory self.window.hidden = YES; + [self.window.rootViewController.presentedViewController.childViewControllers makeObjectsPerformSelector:@selector(removeFromParentViewController)]; + [self.window.rootViewController.presentedViewController dismissViewControllerAnimated:NO completion:nil]; self.window = nil; _visible = NO; @@ -567,37 +576,17 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim } [CATransaction commit]; } --(void) setTitle:(NSString *)title -{ - _title = title; - - UIFont *titleFont = [UIFont boldSystemFontOfSize:17.0]; - - // The UILabels in UIAlertView mysteriously have no paragraph style but STILL have line heights - // I suspect there's some UILabel private API fuckery afoot - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - //[paragrahStyle setLineSpacing:2]; - - NSDictionary *attributes = @{ - NSParagraphStyleAttributeName: paragraphStyle, - NSFontAttributeName: titleFont - }; - - self.titleLabel.attributedText = [[NSAttributedString alloc] initWithString:title attributes:attributes]; - self.titleLabel.textAlignment = NSTextAlignmentCenter; -} - - (void)setMessage:(NSString *)message { _message = message; UIFont *messageFont = [UIFont systemFontOfSize:14.0]; - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; + NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init]; //[paragrahStyle setLineSpacing:2]; NSDictionary *attributes = @{ - NSParagraphStyleAttributeName: paragraphStyle, + NSParagraphStyleAttributeName: paragrahStyle, NSFontAttributeName: messageFont }; @@ -631,7 +620,7 @@ - (id)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in else { labelText = self.otherButtonsTitles[0]; } - + boldButton = YES; lastRow = YES; } @@ -749,35 +738,4 @@ - (UITableViewCell *)buttonCellForIndex:(NSInteger)buttonIndex return [theTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:rowIndex inSection:0]]; } -# pragma mark - to comply with the UIAlertView API - -- (NSInteger)addButtonWithTitle:(NSString *)title -{ - NSString *oldTitle = [self.title copy]; - NSString *oldMessage = [self.message copy]; - NSString *oldCancelTitle = [self.cancelButtonTitle copy]; - NSMutableArray *allTitles = [[NSMutableArray alloc] initWithArray:self.otherButtonsTitles copyItems:YES]; - [allTitles addObject:title]; - [self setupWithTitle:oldTitle message:oldMessage cancelButtonTitle:oldCancelTitle otherButtonTitles:allTitles]; - - return self.numberOfButtons - 1; -} - -- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex -{ - NSString *buttonTitle; - if (self.cancelButtonTitle) { - if (buttonIndex == 0) { - buttonTitle = self.cancelButtonTitle; - } - else { - buttonTitle = [self.otherButtonsTitles objectAtIndex:buttonIndex -1]; - } - } - else { - buttonTitle = [self.otherButtonsTitles objectAtIndex:buttonIndex]; - } - return buttonTitle; -} - @end diff --git a/LMAlertView/LMEmbeddedViewController.h b/LMAlertView/LMEmbeddedViewController.h index f8b10dd..b1d93a0 100644 --- a/LMAlertView/LMEmbeddedViewController.h +++ b/LMAlertView/LMEmbeddedViewController.h @@ -12,5 +12,6 @@ @interface LMEmbeddedViewController : UIViewController @property (weak, nonatomic) LMAlertView *alertView; +@property (nonatomic, retain) UIViewController *controllerToShow; @end diff --git a/LMAlertView/LMEmbeddedViewController.m b/LMAlertView/LMEmbeddedViewController.m index ad8378e..bc467c0 100644 --- a/LMAlertView/LMEmbeddedViewController.m +++ b/LMAlertView/LMEmbeddedViewController.m @@ -19,9 +19,17 @@ - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))comp [self.alertView dismissWithClickedButtonIndex:-1 animated:YES]; } -- (BOOL)shouldAutorotate -{ - return self.alertView.autoRotate; +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + if (self.controllerToShow) { + [self presentViewController:self.controllerToShow animated:NO completion:nil]; + self.controllerToShow = nil; + } + + __weak typeof(self) self_ = self; + [NSNotificationCenter.defaultCenter addObserverForName:@"DismissAlertView" object:nil queue:nil usingBlock:^(NSNotification *note) { + [self_ dismissViewControllerAnimated:NO completion:nil]; + }]; } @end diff --git a/LMAlertViewDemo.xcodeproj/project.pbxproj b/LMAlertViewDemo.xcodeproj/project.pbxproj index 5bacd19..7e05255 100644 --- a/LMAlertViewDemo.xcodeproj/project.pbxproj +++ b/LMAlertViewDemo.xcodeproj/project.pbxproj @@ -27,10 +27,12 @@ 16CCDFA91853296D0059DE8B /* LMTwitterLocationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16CCDFA81853296D0059DE8B /* LMTwitterLocationViewController.m */; }; 16CCDFAC18544C6F0059DE8B /* LMNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 16CCDFAB18544C6F0059DE8B /* LMNavigationController.m */; }; 16CCDFD2185832520059DE8B /* LMModalItemTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 16CCDFD1185832520059DE8B /* LMModalItemTableViewCell.m */; }; + 3DA9B4C1635767EB3DB70354 /* libPods-LMAlertViewDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 01F82A85C2A7AC99B8AC10F5 /* libPods-LMAlertViewDemo.a */; }; E017F5E695B446B2B1B5314D /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B6ABB7B0B6944B929C0CFAFE /* libPods.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 01F82A85C2A7AC99B8AC10F5 /* libPods-LMAlertViewDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LMAlertViewDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 165F9F681831632C00037E82 /* LMAlertView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LMAlertView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 165F9F6B1831632C00037E82 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 165F9F6D1831632C00037E82 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -66,7 +68,8 @@ 16CCDFAB18544C6F0059DE8B /* LMNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LMNavigationController.m; path = ../LMAlertView/LMNavigationController.m; sourceTree = ""; }; 16CCDFD0185832520059DE8B /* LMModalItemTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LMModalItemTableViewCell.h; path = ../LMAlertView/LMModalItemTableViewCell.h; sourceTree = ""; }; 16CCDFD1185832520059DE8B /* LMModalItemTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LMModalItemTableViewCell.m; path = ../LMAlertView/LMModalItemTableViewCell.m; sourceTree = ""; }; - 1FE7E8F0E7304B2287950B17 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; }; + A0A388A4F65DC14E4497135E /* Pods-LMAlertViewDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LMAlertViewDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LMAlertViewDemo/Pods-LMAlertViewDemo.release.xcconfig"; sourceTree = ""; }; + AC87E84A091FDC65B539E239 /* Pods-LMAlertViewDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LMAlertViewDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LMAlertViewDemo/Pods-LMAlertViewDemo.debug.xcconfig"; sourceTree = ""; }; B6ABB7B0B6944B929C0CFAFE /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -80,6 +83,7 @@ 165F9F701831632C00037E82 /* UIKit.framework in Frameworks */, 165F9F6C1831632C00037E82 /* Foundation.framework in Frameworks */, E017F5E695B446B2B1B5314D /* libPods.a in Frameworks */, + 3DA9B4C1635767EB3DB70354 /* libPods-LMAlertViewDemo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -93,7 +97,7 @@ 165F9F711831632C00037E82 /* LMAlertViewDemo */, 165F9F6A1831632C00037E82 /* Frameworks */, 165F9F691831632C00037E82 /* Products */, - 1FE7E8F0E7304B2287950B17 /* Pods.xcconfig */, + 1DDC897C7DE1560E8BF47233 /* Pods */, ); sourceTree = ""; }; @@ -114,6 +118,7 @@ 165F9F6F1831632C00037E82 /* UIKit.framework */, 165F9F8A1831632C00037E82 /* XCTest.framework */, B6ABB7B0B6944B929C0CFAFE /* libPods.a */, + 01F82A85C2A7AC99B8AC10F5 /* libPods-LMAlertViewDemo.a */, ); name = Frameworks; sourceTree = ""; @@ -178,6 +183,15 @@ path = LMAlertViewDemo; sourceTree = ""; }; + 1DDC897C7DE1560E8BF47233 /* Pods */ = { + isa = PBXGroup; + children = ( + AC87E84A091FDC65B539E239 /* Pods-LMAlertViewDemo.debug.xcconfig */, + A0A388A4F65DC14E4497135E /* Pods-LMAlertViewDemo.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -185,11 +199,12 @@ isa = PBXNativeTarget; buildConfigurationList = 165F9F9A1831632C00037E82 /* Build configuration list for PBXNativeTarget "LMAlertViewDemo" */; buildPhases = ( - 4C78D7C540D7469B846C8A07 /* Check Pods Manifest.lock */, + 4C78D7C540D7469B846C8A07 /* [CP] Check Pods Manifest.lock */, 165F9F641831632C00037E82 /* Sources */, 165F9F651831632C00037E82 /* Frameworks */, 165F9F661831632C00037E82 /* Resources */, - D357DFC09ADB4D83BF1003EF /* Copy Pods Resources */, + D357DFC09ADB4D83BF1003EF /* [CP] Copy Pods Resources */, + 4F2C69094B4A6A73A56407CD /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -243,14 +258,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 4C78D7C540D7469B846C8A07 /* Check Pods Manifest.lock */ = { + 4C78D7C540D7469B846C8A07 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -258,19 +273,34 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - D357DFC09ADB4D83BF1003EF /* Copy Pods Resources */ = { + 4F2C69094B4A6A73A56407CD /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LMAlertViewDemo/Pods-LMAlertViewDemo-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + D357DFC09ADB4D83BF1003EF /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "[CP] Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LMAlertViewDemo/Pods-LMAlertViewDemo-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -383,7 +413,7 @@ }; 165F9F9B1831632C00037E82 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1FE7E8F0E7304B2287950B17 /* Pods.xcconfig */; + baseConfigurationReference = AC87E84A091FDC65B539E239 /* Pods-LMAlertViewDemo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -404,7 +434,7 @@ }; 165F9F9C1831632C00037E82 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1FE7E8F0E7304B2287950B17 /* Pods.xcconfig */; + baseConfigurationReference = A0A388A4F65DC14E4497135E /* Pods-LMAlertViewDemo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; diff --git a/LMAlertViewDemo/LMViewController.m b/LMAlertViewDemo/LMViewController.m index e1e258c..fd225bb 100644 --- a/LMAlertViewDemo/LMViewController.m +++ b/LMAlertViewDemo/LMViewController.m @@ -97,18 +97,18 @@ - (IBAction)nativeButtonTapped:(id)sender - (IBAction)customButtonTapped:(id)sender { - LMAlertView *alertView = [[LMAlertView alloc] initWithTitle:@"Test" message:@"Message here" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; - - //[alertView addButtonWithTitle:@"3rd"]; - for (NSInteger titleIndex = 0; titleIndex < alertView.numberOfButtons; titleIndex++) { - NSLog(@"%@: button title for index %i is: %@", [alertView class], titleIndex, [alertView buttonTitleAtIndex:titleIndex]); - } - - NSLog(@"%@: First other button index: %li", [alertView class], (long)alertView.firstOtherButtonIndex); - NSLog(@"%@: Cancel button index: %li", [alertView class], (long)alertView.cancelButtonIndex); - NSLog(@"%@: Number of buttons: %li", [alertView class], (long)alertView.numberOfButtons); - - [alertView show]; +// LMAlertView *alertView = [[LMAlertView alloc] initWithTitle:@"Test" message:@"Message here" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; +// +// //[alertView addButtonWithTitle:@"3rd"]; +// for (NSInteger titleIndex = 0; titleIndex < alertView.numberOfButtons; titleIndex++) { +// NSLog(@"%@: button title for index %i is: %@", [alertView class], titleIndex, [alertView buttonTitleAtIndex:titleIndex]); +// } +// +// NSLog(@"%@: First other button index: %li", [alertView class], (long)alertView.firstOtherButtonIndex); +// NSLog(@"%@: Cancel button index: %li", [alertView class], (long)alertView.cancelButtonIndex); +// NSLog(@"%@: Number of buttons: %li", [alertView class], (long)alertView.numberOfButtons); +// +// [alertView show]; } - (IBAction)ratingButtonTapped:(id)sender diff --git a/Podfile b/Podfile index 8654ed5..66d8fd3 100644 --- a/Podfile +++ b/Podfile @@ -1,6 +1,6 @@ -platform :ios, '7.0' - -pod 'EDStarRating', '~> 1.1' -pod 'RBBAnimation', '~> 0.3.0' -pod 'CAAnimationBlocks', '~> 0.0.1' -pod 'LMFixedTextView', :git => 'https://github.com/lmcd/LMFixedTextView.git' \ No newline at end of file +target "LMAlertViewDemo" do + pod 'EDStarRating', '~> 1.1' + pod 'RBBAnimation', '~> 0.3.0' + pod 'CAAnimationBlocks', '~> 0.0.1' + pod 'LMFixedTextView', :git => 'https://github.com/lmcd/LMFixedTextView.git' +end \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index 88b5970..3523531 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -14,10 +14,17 @@ EXTERNAL SOURCES: LMFixedTextView: :git: https://github.com/lmcd/LMFixedTextView.git +CHECKOUT OPTIONS: + LMFixedTextView: + :commit: 2915e66e42c7a459f31aab360663e2599059dcd2 + :git: https://github.com/lmcd/LMFixedTextView.git + SPEC CHECKSUMS: - CAAnimationBlocks: b70f877c5b92734abef270152187d3287d84e8f8 - EDStarRating: 6761f41fd040f1cde155e2885dddc96461620f67 - LMFixedTextView: 794f1423096e30f88a856ef49a791af08e5c6efe - RBBAnimation: e7f31ed62f760f3caf120b5d943267bd9a8e1f64 + CAAnimationBlocks: 1aaca5fb6447a95d83b20cc786992956ef46e4ee + EDStarRating: a41a6440a945020745d0e9ff8ada7d1afa952114 + LMFixedTextView: e7ca1e04dbbe3615ce9429dfec71472bdefea85f + RBBAnimation: cb6cb419f511434ce932f7d0fabf369612fafb4e + +PODFILE CHECKSUM: a48fbb861dc5b9fd3e0fd3ebddae7315b28b5246 -COCOAPODS: 0.28.0 +COCOAPODS: 1.0.1