Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 7 improvements #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 100 additions & 33 deletions Classes/Popover/WEPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,34 @@ - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
return [self presentPopoverFromRect:rect inView:v permittedArrowDirections:arrowDirections animated:animated];
}

- (void)presentPopoverFromRect:(CGRect)rect
- (CGSize)contentPopoverContentSize
{
CGSize contentPopoverContentSize;

contentPopoverContentSize = (([contentViewController respondsToSelector:@selector(preferredContentSize)]) ?
contentViewController.preferredContentSize :
CGSizeZero);

if (CGSizeEqualToSize(contentPopoverContentSize, CGSizeZero)) {
contentPopoverContentSize = contentViewController.contentSizeForViewInPopover;
}

return contentPopoverContentSize;
}

- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)theView
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated {
BOOL iOSSevenOrAbove = ([UIDevice currentDevice].systemVersion.doubleValue >= 7.0);

[self dismissPopoverAnimated:NO];

//First force a load view for the contentViewController so the popoverContentSize is properly initialized
[contentViewController view];

if (CGSizeEqualToSize(popoverContentSize, CGSizeZero)) {
popoverContentSize = contentViewController.contentSizeForViewInPopover;
popoverContentSize = [self contentPopoverContentSize];
}

CGRect displayArea = [self displayAreaForView:theView];
Expand All @@ -148,7 +163,7 @@ - (void)presentPopoverFromRect:(CGRect)rect
popoverArrowDirection = containerView.arrowDirection;

UIView *keyView = self.keyView;

backgroundView = [[WETouchableView alloc] initWithFrame:keyView.bounds];
backgroundView.contentMode = UIViewContentModeScaleToFill;
backgroundView.autoresizingMask = ( UIViewAutoresizingFlexibleLeftMargin |
Expand All @@ -157,9 +172,13 @@ - (void)presentPopoverFromRect:(CGRect)rect
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleBottomMargin);
backgroundView.backgroundColor = [UIColor clearColor];

/* On iOS 7, the background should gray-out everything but the popup */
backgroundView.backgroundColor = (iOSSevenOrAbove ?
[[UIColor lightGrayColor] colorWithAlphaComponent:0.4] :
[UIColor clearColor]);
backgroundView.delegate = self;
backgroundView.alpha = 0.0;
[keyView addSubview:backgroundView];

containerView.frame = [theView convertRect:containerView.frame toView:backgroundView];
Expand All @@ -172,7 +191,16 @@ - (void)presentPopoverFromRect:(CGRect)rect

self.view = containerView;
[self updateBackgroundPassthroughViews];


/* On iOS 7, the content view should have rounded corners.
* We don't apply this to the containerView itself, as that includes the arrow.
*/
if (iOSSevenOrAbove) {
containerView.contentView.layer.cornerRadius = 8.0f;
containerView.contentView.layer.masksToBounds = YES;
}


if ([self forwardAppearanceMethods]) {
[contentViewController viewWillAppear:animated];
}
Expand All @@ -187,14 +215,16 @@ - (void)presentPopoverFromRect:(CGRect)rect
animations:^{

self.view.alpha = 1.0;

backgroundView.alpha = 1.0;

} completion:^(BOOL finished) {

[self animationDidStop:@"FadeIn" finished:[NSNumber numberWithBool:finished] context:nil];
}];

} else {
if ([self forwardAppearanceMethods]) {
backgroundView.alpha = 1.0;
[contentViewController viewDidAppear:animated];
}
}
Expand Down Expand Up @@ -223,7 +253,7 @@ - (void)repositionPopoverFromRect:(CGRect)rect
}

if (CGSizeEqualToSize(popoverContentSize, CGSizeZero)) {
popoverContentSize = contentViewController.contentSizeForViewInPopover;
popoverContentSize = [self contentPopoverContentSize];
}

CGRect displayArea = [self displayAreaForView:theView];
Expand Down Expand Up @@ -277,6 +307,7 @@ - (UIView *)keyView {
return self.parentView;
} else {
UIWindow *w = [[UIApplication sharedApplication] keyWindow];

if (w.subviews.count > 0) {
return [w.subviews objectAtIndex:0];
} else {
Expand Down Expand Up @@ -339,38 +370,74 @@ - (CGRect)displayAreaForView:(UIView *)theView {
displayArea = [(id <WEPopoverParentView>)theView displayAreaForPopover];
} else {
UIView *keyView = [self keyView];
displayArea = [keyView convertRect:keyView.bounds toView:theView];

displayArea = [keyView convertRect:keyView.bounds toView:theView];

if (CGRectEqualToRect(keyView.frame, [[UIApplication sharedApplication] keyWindow].frame) &&
([UIApplication sharedApplication].statusBarHidden == NO)) {
/* In iOS 7 the display area will overlap the status bar, which we don't want */
#define kStatusBarHeight 20.0f
displayArea.origin.y += kStatusBarHeight;
displayArea.size.height -= kStatusBarHeight;
}
}
return displayArea;
}

//Enable to use the simple popover style
- (WEPopoverContainerViewProperties *)defaultContainerViewProperties {
WEPopoverContainerViewProperties *ret = [[WEPopoverContainerViewProperties new] autorelease];
WEPopoverContainerViewProperties *props = [[WEPopoverContainerViewProperties new] autorelease];
BOOL iOSSevenOrAbove = ([UIDevice currentDevice].systemVersion.doubleValue >= 7.0);

NSString *bgImageName;
CGFloat bgMargin;
CGFloat contentMargin;

if (iOSSevenOrAbove) {
/* On iOS 7, there is no background nor content margin, and the arrow is white */
bgImageName = nil;

bgMargin = 0.0;
contentMargin = 0.0;

props.upArrowImageName = @"popoverArrowUp-white.png";
props.downArrowImageName = @"popoverArrowDown-white.png";
props.leftArrowImageName = @"popoverArrowLeft-white.png";
props.rightArrowImageName = @"popoverArrowRight-white.png";

} else {
bgImageName = @"popoverBg.png";
bgMargin = 0.0;
contentMargin = 4.0;

props.upArrowImageName = @"popoverArrowUp.png";
props.downArrowImageName = @"popoverArrowDown.png";
props.leftArrowImageName = @"popoverArrowLeft.png";
props.rightArrowImageName = @"popoverArrowRight.png";
}

CGFloat bgCapSize = 0.0;

// These constants are determined by the popoverBg.png image file and are image dependent

bgMargin = 13; // margin width of 13 pixels on all sides popoverBg.png (62 pixels wide - 36 pixel background) / 2 == 26 / 2 == 13
bgCapSize = 31; // ImageSize/2 == 62 / 2 == 31 pixels

CGSize imageSize = CGSizeMake(30.0f, 30.0f);
NSString *bgImageName = @"popoverBgSimple.png";
CGFloat bgMargin = 6.0;
CGFloat contentMargin = 2.0;
props.leftBgMargin = bgMargin;
props.rightBgMargin = bgMargin;
props.topBgMargin = bgMargin;
props.bottomBgMargin = bgMargin;
props.leftBgCapSize = bgCapSize;
props.topBgCapSize = bgCapSize;
props.bgImageName = bgImageName;
props.leftContentMargin = contentMargin;
props.rightContentMargin = contentMargin - 1; // Need to shift one pixel for border to look correct
props.topContentMargin = contentMargin;
props.bottomContentMargin = contentMargin;

ret.leftBgMargin = bgMargin;
ret.rightBgMargin = bgMargin;
ret.topBgMargin = bgMargin;
ret.bottomBgMargin = bgMargin;
ret.leftBgCapSize = imageSize.width/2;
ret.topBgCapSize = imageSize.height/2;
ret.bgImageName = bgImageName;
ret.leftContentMargin = contentMargin;
ret.rightContentMargin = contentMargin;
ret.topContentMargin = contentMargin;
ret.bottomContentMargin = contentMargin;
ret.arrowMargin = 1.0;
props.arrowMargin = 4.0;

ret.upArrowImageName = @"popoverArrowUpSimple.png";
ret.downArrowImageName = @"popoverArrowDownSimple.png";
ret.leftArrowImageName = @"popoverArrowLeftSimple.png";
ret.rightArrowImageName = @"popoverArrowRightSimple.png";
return ret;
return props;
}

@end
Binary file added popoverArrowDown-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowDown-white@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowLeft-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowLeft-white@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowRight-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowRight-white@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowUp-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added popoverArrowUp-white@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.