Skip to content

Commit

Permalink
Fixed status bar style and crash when windowPrevious is not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Friend-LGA committed Oct 27, 2015
1 parent 4a7acb4 commit c8dbcbe
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 59 deletions.
4 changes: 3 additions & 1 deletion Demo/LGAlertViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
4A3B78711AD2A28300DB8642 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4A3B78701AD2A28300DB8642 /* Images.xcassets */; };
4A3B788B1AD2A93D00DB8642 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3B788A1AD2A93D00DB8642 /* TableViewController.m */; };
4A3B788E1AD2B29F00DB8642 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3B788D1AD2B29F00DB8642 /* NavigationController.m */; };
4ABF191C1BDA895200A12B6E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4ABF191B1BDA895200A12B6E /* LaunchScreen.storyboard */; settings = {ASSET_TAGS = (); }; };
4ABF191C1BDA895200A12B6E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4ABF191B1BDA895200A12B6E /* LaunchScreen.storyboard */; };
92E830BBF9A0E9733AA1BC7E /* libPods-LGAlertViewDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 623B5C352E52555F577FBF72 /* libPods-LGAlertViewDemo.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -321,6 +321,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
INFOPLIST_FILE = LGAlertViewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -334,6 +335,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
INFOPLIST_FILE = LGAlertViewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
4 changes: 3 additions & 1 deletion Demo/LGAlertViewDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
//

#import "AppDelegate.h"
#import "TableViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.navigationController = [NavigationController new];
TableViewController *tableViewController = [TableViewController new];
self.navigationController = [[NavigationController alloc] initWithRootViewController:tableViewController];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
Expand Down
28 changes: 16 additions & 12 deletions Demo/LGAlertViewDemo/NavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@
//

#import "NavigationController.h"
#import "TableViewController.h"

@interface NavigationController ()

@property (strong, nonatomic) TableViewController *tableViewController;

@end

@implementation NavigationController

- (id)init
- (void)viewDidLoad
{
self = [super init];
if (self)
{
self.tableViewController = [TableViewController new];
[self setViewControllers:@[self.tableViewController]];
}
return self;
[super viewDidLoad];

self.navigationBar.barTintColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f];
self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
}

- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
return YES;
}

- (BOOL)prefersStatusBarHidden
{
return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}

@end
1 change: 0 additions & 1 deletion Demo/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '6.0'
inhibit_all_warnings!

xcodeproj 'LGAlertViewDemo'

Expand Down
4 changes: 2 additions & 2 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- LGAlertView (1.0.4)
- LGAlertView (1.1.1)

DEPENDENCIES:
- LGAlertView (from `../`)
Expand All @@ -9,6 +9,6 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
LGAlertView: 2c0405af11a4622accd2acf06fa1fb0eadb1ccf7
LGAlertView: 6d09e9aef4878d78c5f182ac196f1ea829c9ff61

COCOAPODS: 0.39.0
2 changes: 1 addition & 1 deletion LGAlertView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'LGAlertView'
s.version = '1.1.0'
s.version = '1.1.1'
s.platform = :ios, '6.0'
s.license = 'MIT'
s.homepage = 'https://github.com/Friend-LGA/LGAlertView'
Expand Down
58 changes: 28 additions & 30 deletions LGAlertView/LGAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ @interface LGAlertView () <UITableViewDataSource, UITableViewDelegate, UITextFie
@property (assign, nonatomic, getter=isExists) BOOL exists;

@property (strong, nonatomic) UIWindow *window;
@property (assign, nonatomic) UIWindow *windowPrevious;
@property (assign, nonatomic) UIWindow *windowNotice;
@property (strong, nonatomic) UIWindow *windowPrevious;
@property (strong, nonatomic) UIWindow *windowNotice;

@property (strong, nonatomic) UIView *view;

Expand Down Expand Up @@ -208,6 +208,11 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi

#endif

- (UIStatusBarStyle)preferredStatusBarStyle
{
return [UIApplication sharedApplication].statusBarStyle;
}

@end

@implementation LGAlertView
Expand Down Expand Up @@ -998,15 +1003,16 @@ - (void)windowVisibleChanged:(NSNotification *)notification
//NSLog(@"%@", NSStringFromClass([window class]));

if ([NSStringFromClass([window class]) isEqualToString:@"UITextEffectsWindow"] ||
[NSStringFromClass([window class]) isEqualToString:@"UIRemoteKeyboardWindow"]) return;
[NSStringFromClass([window class]) isEqualToString:@"UIRemoteKeyboardWindow"] ||
[window isEqual:_window]) return;

if (notification.name == UIWindowDidBecomeVisibleNotification)
{
if ([window isEqual:_windowPrevious])
{
window.hidden = YES;
}
else if (![window isEqual:_window] && !_windowNotice)
else if (!_windowNotice)
{
_windowNotice = window;

Expand All @@ -1015,19 +1021,11 @@ - (void)windowVisibleChanged:(NSNotification *)notification
}
else if (notification.name == UIWindowDidBecomeHiddenNotification)
{
__weak UIView *view = window.subviews.lastObject;

if (![window isEqual:_window] && [window isEqual:_windowNotice])
if ([window isEqual:_windowNotice])
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void)
{
if (!view)
{
_windowNotice = nil;

[_window makeKeyAndVisible];
}
});
_windowNotice = nil;

[_window makeKeyAndVisible];
}
}
}
Expand Down Expand Up @@ -1241,7 +1239,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
label.adjustsFontSizeToFitWidth = _destructiveButtonAdjustsFontSizeToFitWidth;
label.minimumScaleFactor = _destructiveButtonMinimumScaleFactor;

CGSize size = [label sizeThatFits:CGSizeMake(tableView.frame.size.width-kLGAlertViewInnerMarginW*2, CGFLOAT_MAX)];
CGSize size = [label sizeThatFits:CGSizeMake(tableView.frame.size.width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)];
size.height += kLGAlertViewButtonTitleMarginH*2;

if (size.height < _buttonsHeight)
Expand All @@ -1262,7 +1260,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
label.adjustsFontSizeToFitWidth = _cancelButtonAdjustsFontSizeToFitWidth;
label.minimumScaleFactor = _cancelButtonMinimumScaleFactor;

CGSize size = [label sizeThatFits:CGSizeMake(tableView.frame.size.width-kLGAlertViewInnerMarginW*2, CGFLOAT_MAX)];
CGSize size = [label sizeThatFits:CGSizeMake(tableView.frame.size.width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)];
size.height += kLGAlertViewButtonTitleMarginH*2;

if (size.height < _buttonsHeight)
Expand All @@ -1283,7 +1281,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
label.adjustsFontSizeToFitWidth = _buttonsAdjustsFontSizeToFitWidth;
label.minimumScaleFactor = _buttonsMinimumScaleFactor;

CGSize size = [label sizeThatFits:CGSizeMake(tableView.frame.size.width-kLGAlertViewInnerMarginW*2, CGFLOAT_MAX)];
CGSize size = [label sizeThatFits:CGSizeMake(tableView.frame.size.width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)];
size.height += kLGAlertViewButtonTitleMarginH*2;

if (size.height < _buttonsHeight)
Expand Down Expand Up @@ -1540,8 +1538,8 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = _titleFont;

CGSize titleLabelSize = [_titleLabel sizeThatFits:CGSizeMake(width-kLGAlertViewInnerMarginW*2, CGFLOAT_MAX)];
CGRect titleLabelFrame = CGRectMake(kLGAlertViewInnerMarginW, kLGAlertViewInnerMarginH, width-kLGAlertViewInnerMarginW*2, titleLabelSize.height);
CGSize titleLabelSize = [_titleLabel sizeThatFits:CGSizeMake(width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)];
CGRect titleLabelFrame = CGRectMake(kLGAlertViewPaddingW, kLGAlertViewInnerMarginH, width-kLGAlertViewPaddingW*2, titleLabelSize.height);
if ([UIScreen mainScreen].scale == 1.f)
titleLabelFrame = CGRectIntegral(titleLabelFrame);

Expand All @@ -1564,8 +1562,8 @@ - (void)subviewsInvalidateWithSize:(CGSize)size

if (!offsetY) offsetY = kLGAlertViewInnerMarginH/2;

CGSize messageLabelSize = [_messageLabel sizeThatFits:CGSizeMake(width-kLGAlertViewInnerMarginW*2, CGFLOAT_MAX)];
CGRect messageLabelFrame = CGRectMake(kLGAlertViewInnerMarginW, offsetY+kLGAlertViewInnerMarginH/2, width-kLGAlertViewInnerMarginW*2, messageLabelSize.height);
CGSize messageLabelSize = [_messageLabel sizeThatFits:CGSizeMake(width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)];
CGRect messageLabelFrame = CGRectMake(kLGAlertViewPaddingW, offsetY+kLGAlertViewInnerMarginH/2, width-kLGAlertViewPaddingW*2, messageLabelSize.height);
if ([UIScreen mainScreen].scale == 1.f)
messageLabelFrame = CGRectIntegral(messageLabelFrame);

Expand Down Expand Up @@ -1613,7 +1611,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
if (_progressViewTrackImage)
_progressView.trackImage = _progressViewTrackImage;

CGRect progressViewFrame = CGRectMake(kLGAlertViewInnerMarginW, offsetY+kLGAlertViewInnerMarginH, width-kLGAlertViewInnerMarginW*2, _progressView.frame.size.height);
CGRect progressViewFrame = CGRectMake(kLGAlertViewPaddingW, offsetY+kLGAlertViewInnerMarginH, width-kLGAlertViewPaddingW*2, _progressView.frame.size.height);
if ([UIScreen mainScreen].scale == 1.f)
progressViewFrame = CGRectIntegral(progressViewFrame);

Expand All @@ -1630,8 +1628,8 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
_progressLabel.backgroundColor = [UIColor clearColor];
_progressLabel.font = _progressLabelFont;

CGSize progressLabelSize = [_progressLabel sizeThatFits:CGSizeMake(width-kLGAlertViewInnerMarginW*2, CGFLOAT_MAX)];
CGRect progressLabelFrame = CGRectMake(kLGAlertViewInnerMarginW, offsetY+kLGAlertViewInnerMarginH/2, width-kLGAlertViewInnerMarginW*2, progressLabelSize.height);
CGSize progressLabelSize = [_progressLabel sizeThatFits:CGSizeMake(width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)];
CGRect progressLabelFrame = CGRectMake(kLGAlertViewPaddingW, offsetY+kLGAlertViewInnerMarginH/2, width-kLGAlertViewPaddingW*2, progressLabelSize.height);
if ([UIScreen mainScreen].scale == 1.f)
progressLabelFrame = CGRectIntegral(progressLabelFrame);

Expand Down Expand Up @@ -1699,7 +1697,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
[_destructiveButton setTitleColor:_destructiveButtonTitleColorHighlighted forState:UIControlStateSelected];
[_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted];
[_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorHighlighted] forState:UIControlStateSelected];
_destructiveButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW, kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW);
_destructiveButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW);
_destructiveButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
if (_destructiveButtonTextAlignment == NSTextAlignmentCenter)
_destructiveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
Expand Down Expand Up @@ -1730,7 +1728,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
[_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateSelected];
[_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted];
[_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateSelected];
_cancelButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW, kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW);
_cancelButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW);
_cancelButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
if (_cancelButtonTextAlignment == NSTextAlignmentCenter)
_cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
Expand Down Expand Up @@ -1761,7 +1759,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
[_firstButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateSelected];
[_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateHighlighted];
[_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateSelected];
_firstButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW, kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW);
_firstButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW);
_firstButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
if (_buttonsTextAlignment == NSTextAlignmentCenter)
_firstButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
Expand Down Expand Up @@ -1791,7 +1789,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size
[_secondButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateSelected];
[_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateHighlighted];
[_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateSelected];
_secondButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW, kLGAlertViewButtonTitleMarginH, kLGAlertViewInnerMarginW);
_secondButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW);
_secondButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
if (_buttonsTextAlignment == NSTextAlignmentCenter)
_secondButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
Expand Down
2 changes: 1 addition & 1 deletion LGAlertView/LGAlertViewShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
// SOFTWARE.
//

static CGFloat const kLGAlertViewInnerMarginW = 10.f;
static CGFloat const kLGAlertViewPaddingW = 10.f;
20 changes: 10 additions & 10 deletions LGAlertView/LGAlertViewTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ - (instancetype)init

- (CGRect)textRectForBounds:(CGRect)bounds
{
bounds.origin.x += kLGAlertViewInnerMarginW;
bounds.size.width -= kLGAlertViewInnerMarginW*2;
bounds.origin.x += kLGAlertViewPaddingW;
bounds.size.width -= kLGAlertViewPaddingW*2;

if ([UIDevice currentDevice].systemVersion.floatValue < 7.0)
{
Expand All @@ -58,12 +58,12 @@ - (CGRect)textRectForBounds:(CGRect)bounds

if (self.leftView)
{
bounds.origin.x += (self.leftView.frame.size.width+kLGAlertViewInnerMarginW);
bounds.size.width -= (self.leftView.frame.size.width+kLGAlertViewInnerMarginW);
bounds.origin.x += (self.leftView.frame.size.width+kLGAlertViewPaddingW);
bounds.size.width -= (self.leftView.frame.size.width+kLGAlertViewPaddingW);
}

if (self.rightView)
bounds.size.width -= (self.rightView.frame.size.width+kLGAlertViewInnerMarginW);
bounds.size.width -= (self.rightView.frame.size.width+kLGAlertViewPaddingW);
else if (self.clearButtonMode == UITextFieldViewModeAlways)
bounds.size.width -= 20.f;

Expand All @@ -72,8 +72,8 @@ - (CGRect)textRectForBounds:(CGRect)bounds

- (CGRect)editingRectForBounds:(CGRect)bounds
{
bounds.origin.x += kLGAlertViewInnerMarginW;
bounds.size.width -= kLGAlertViewInnerMarginW*2;
bounds.origin.x += kLGAlertViewPaddingW;
bounds.size.width -= kLGAlertViewPaddingW*2;

if ([UIDevice currentDevice].systemVersion.floatValue < 7.0)
{
Expand All @@ -83,12 +83,12 @@ - (CGRect)editingRectForBounds:(CGRect)bounds

if (self.leftView)
{
bounds.origin.x += (self.leftView.frame.size.width+kLGAlertViewInnerMarginW);
bounds.size.width -= (self.leftView.frame.size.width+kLGAlertViewInnerMarginW);
bounds.origin.x += (self.leftView.frame.size.width+kLGAlertViewPaddingW);
bounds.size.width -= (self.leftView.frame.size.width+kLGAlertViewPaddingW);
}

if (self.rightView)
bounds.size.width -= (self.rightView.frame.size.width+kLGAlertViewInnerMarginW);
bounds.size.width -= (self.rightView.frame.size.width+kLGAlertViewPaddingW);
else if (self.clearButtonMode == UITextFieldViewModeAlways)
bounds.size.width -= 20.f;

Expand Down

0 comments on commit c8dbcbe

Please sign in to comment.