diff --git a/IBActionSheet.podspec b/IBActionSheet.podspec index 7cbd1b8..e28ac1d 100644 --- a/IBActionSheet.podspec +++ b/IBActionSheet.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'IBActionSheet' - s.version = '0.0.3' + s.version = '0.0.4' s.summary = 'Customizable iOS 7 style UIActionSheet' s.homepage = 'https://github.com/ianb821/IBActionSheet' @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.author = { 'Ian Burns' => 'ianb821@gmail.com' } s.platform = :ios, '5.0' - s.source = { :git => 'https://github.com/ianb821/IBActionSheet.git', :tag => '0.0.3' } + s.source = { :git => 'https://github.com/irtemed88/IBActionSheet.git', :tag => '0.0.4' } s.source_files = 'IBActionSheetSample/IBActionSheetSample/IBActionSheet.{h,m}' s.framework = 'QuartzCore' diff --git a/IBActionSheetSample/IBActionSheetSample/IBActionSheet.m b/IBActionSheetSample/IBActionSheetSample/IBActionSheet.m index d931a07..f4c5cd8 100755 --- a/IBActionSheetSample/IBActionSheetSample/IBActionSheet.m +++ b/IBActionSheetSample/IBActionSheetSample/IBActionSheet.m @@ -23,16 +23,29 @@ #import "IBActionSheet.h" -#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height -#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width - #pragma mark - IBActionSheet +CGRect adjustedScreenBounds() +{ + // With iOS 8 it is no longer necessary to swap screen width/height when in landscape. + CGRect bounds = [[UIScreen mainScreen] bounds]; + BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]); + if (SYSTEM_VERSION_LESS_THAN(@"8.0") && isLandscape) { + CGFloat temp = bounds.size.width; + bounds.size.width = bounds.size.height; + bounds.size.height = temp; + } + + return bounds; +} + + @implementation IBActionSheet { NSInteger _selectedButtonIndex; } + #pragma mark IBActionSheet Set up methods - (id)init { @@ -45,7 +58,8 @@ - (id)init { self.cancelButtonIndex = -1; self.destructiveButtonIndex = -1; - self.transparentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds))]; + CGRect bounds = adjustedScreenBounds(); + self.transparentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds), CGRectGetHeight(bounds))]; self.transparentView.backgroundColor = [UIColor blackColor]; self.transparentView.alpha = 0.0f; @@ -342,14 +356,7 @@ - (id)initWithTitle:(NSString *)title callback:(IBActionCallback)callback cancel - (void)setUpTheActionSheet { float height; - float width; - - if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { - width = CGRectGetWidth([UIScreen mainScreen].bounds); - } else { - width = CGRectGetHeight([UIScreen mainScreen].bounds); - } - + float width = CGRectGetWidth(adjustedScreenBounds()); // slight adjustment to take into account non-retina devices if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] @@ -672,20 +679,8 @@ - (void)showInView:(UIView *)theView { [theView insertSubview:self.transparentView belowSubview:self]; - CGRect theScreenRect = [UIScreen mainScreen].bounds; - - float height; - float x; - - if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { - height = CGRectGetHeight(theScreenRect); - x = CGRectGetWidth(theView.frame) / 2.0; - self.transparentView.frame = CGRectMake(self.transparentView.center.x, self.transparentView.center.y, CGRectGetWidth(theScreenRect), CGRectGetHeight(theScreenRect)); - } else { - height = CGRectGetWidth(theScreenRect); - x = CGRectGetHeight(theView.frame) / 2.0; - self.transparentView.frame = CGRectMake(self.transparentView.center.x, self.transparentView.center.y, CGRectGetHeight(theScreenRect), CGRectGetWidth(theScreenRect)); - } + float height = CGRectGetHeight(adjustedScreenBounds()); + float x = CGRectGetWidth(theView.frame) / 2.0; self.center = CGPointMake(x, height + CGRectGetHeight(self.frame) / 2.0); self.transparentView.center = CGPointMake(x, height / 2.0); @@ -738,7 +733,7 @@ - (void)removeFromView { options:UIViewAnimationOptionCurveEaseOut animations:^() { self.transparentView.alpha = 0.0f; - self.center = CGPointMake(CGRectGetWidth(self.frame) / 2.0, CGRectGetHeight([UIScreen mainScreen].bounds) + CGRectGetHeight(self.frame) / 2.0); + self.center = CGPointMake(CGRectGetWidth(self.frame) / 2.0, CGRectGetHeight(adjustedScreenBounds()) + CGRectGetHeight(self.frame) / 2.0); } completion:^(BOOL finished) { [self.transparentView removeFromSuperview]; @@ -764,7 +759,7 @@ - (void)removeFromView { } self.transparentView.alpha = 0.0f; - self.center = CGPointMake(CGRectGetWidth(self.frame) / 2.0, CGRectGetHeight([UIScreen mainScreen].bounds) + CGRectGetHeight(self.frame) / 2.0); + self.center = CGPointMake(CGRectGetWidth(self.frame) / 2.0, CGRectGetHeight(adjustedScreenBounds()) + CGRectGetHeight(self.frame) / 2.0); } completion:^(BOOL finished) { [self.transparentView removeFromSuperview]; @@ -785,8 +780,8 @@ - (void)removeFromView { - (void)rotateToCurrentOrientation { - float width = SCREEN_WIDTH; - float height = SCREEN_HEIGHT; + float width = adjustedScreenBounds().size.width; + float height = adjustedScreenBounds().size.height; if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { @@ -950,13 +945,7 @@ @implementation IBActionSheetButton - (id)init { - float width; - - if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { - width = CGRectGetWidth([UIScreen mainScreen].bounds); - } else { - width = CGRectGetHeight([UIScreen mainScreen].bounds); - } + float width = adjustedScreenBounds().size.width; self = [self initWithFrame:CGRectMake(0, 0, width - 16, 44)]; self.backgroundColor = [UIColor whiteColor]; @@ -1000,10 +989,11 @@ - (void)setTextColor:(UIColor *)color { - (void)resizeForPortraitOrientation { - self.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds) - 16, CGRectGetHeight(self.frame)); + self.frame = CGRectMake(0, 0, CGRectGetWidth(adjustedScreenBounds()) - 16, CGRectGetHeight(self.frame)); switch (self.cornerType) { case IBActionSheetButtonCornerTypeNoCornersRounded: + [self setMaskTo:self byRoundingCorners:0]; break; case IBActionSheetButtonCornerTypeTopCornersRounded: { @@ -1026,10 +1016,11 @@ - (void)resizeForPortraitOrientation { } - (void)resizeForLandscapeOrientation { - self.frame = CGRectMake(0, 0, CGRectGetHeight([UIScreen mainScreen].bounds) - 16, CGRectGetHeight(self.frame)); + self.frame = CGRectMake(0, 0, CGRectGetWidth(adjustedScreenBounds()) - 16, CGRectGetHeight(self.frame)); switch (self.cornerType) { case IBActionSheetButtonCornerTypeNoCornersRounded: + [self setMaskTo:self byRoundingCorners:0]; break; case IBActionSheetButtonCornerTypeTopCornersRounded: { @@ -1073,14 +1064,12 @@ - (id)initWithTitle:(NSString *)title font:(UIFont *)font { self = [self init]; - float width; + float width = adjustedScreenBounds().size.width; float labelBuffer; if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { - width = CGRectGetWidth([UIScreen mainScreen].bounds); labelBuffer = 44; } else { - width = CGRectGetHeight([UIScreen mainScreen].bounds); labelBuffer = 24; } @@ -1118,15 +1107,15 @@ - (id)initWithTitle:(NSString *)title font:(UIFont *)font { - (void)resizeForPortraitOrientation { - self.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds) - 16, CGRectGetHeight(self.frame)); - self.titleLabel.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds) - 24, 44); + self.frame = CGRectMake(0, 0, CGRectGetWidth(adjustedScreenBounds()) - 16, CGRectGetHeight(self.frame)); + self.titleLabel.frame = self.bounds; [self setMaskTo:self byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight]; } - (void)resizeForLandscapeOrientation { - self.frame = CGRectMake(0, 0, CGRectGetHeight([UIScreen mainScreen].bounds) - 16, CGRectGetHeight(self.frame)); - self.titleLabel.frame = CGRectMake(0, 0, CGRectGetHeight([UIScreen mainScreen].bounds) - 44, 44); + self.frame = CGRectMake(0, 0, CGRectGetWidth(adjustedScreenBounds()) - 16, CGRectGetHeight(self.frame)); + self.titleLabel.frame = self.bounds; [self setMaskTo:self byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight]; }