Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/irtemed88/IBActionSheet i…
Browse files Browse the repository at this point in the history
…nto irtemed88-master

# Conflicts:
#	IBActionSheet.podspec
  • Loading branch information
ianb821 committed Sep 25, 2015
2 parents df8c171 + 95d6562 commit b1b4778
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 48 deletions.
4 changes: 2 additions & 2 deletions IBActionSheet.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.author = { 'Ian Burns' => '[email protected]' }

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'
Expand Down
81 changes: 35 additions & 46 deletions IBActionSheetSample/IBActionSheetSample/IBActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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])) {

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit b1b4778

Please sign in to comment.