Skip to content
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
12 changes: 10 additions & 2 deletions WYPopoverController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ Pod::Spec.new do |s|

s.source = { :git => 'https://github.com/sammcewan/WYPopoverController.git', :tag => '0.3.8' }

s.source_files = 'WYPopoverController/*.{h,m}'
s.requires_arc = true

s.ios.deployment_target = '6.0'
s.ios.frameworks = 'QuartzCore', 'UIKit', 'CoreGraphics'

s.subspec 'Core' do |core|
core.source_files = 'WYPopoverController/*.{h,m}'
core.frameworks = 'QuartzCore', 'UIKit', 'CoreGraphics'
end

s.subspec 'AppExtension' do |app_extension|
app_extension.dependency 'WYPopoverController/Core'
app_extension.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) WY_APP_EXTENSIONS=1' }
end
end
35 changes: 25 additions & 10 deletions WYPopoverController/WYPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ of this software and associated documentation files (the "Software"), to deal

#define WY_IS_IOS_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#if !defined(WY_APP_EXTENSIONS)
#define WY_USER_INTERFACE_ORIENTATION [[UIApplication sharedApplication] statusBarOrientation]
#else
#define WY_USER_INTERFACE_ORIENTATION UIInterfaceOrientationPortrait
#endif


////////////////////////////////////////////////////////////////////////////////////////////////////////

@interface WYKeyboardListener : NSObject
Expand Down Expand Up @@ -1686,13 +1693,15 @@ - (CGSize)topViewControllerContentSize {
#pragma clang diagnostic pop
}

#if !defined(WY_APP_EXTENSIONS)
if (CGSizeEqualToSize(result, CGSizeZero)) {
CGSize windowSize = [[UIApplication sharedApplication] keyWindow].bounds.size;

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

result = CGSizeMake(UIInterfaceOrientationIsPortrait(orientation) ? windowSize.width : windowSize.height, UIInterfaceOrientationIsLandscape(orientation) ? windowSize.width : windowSize.height);
}
#endif

return result;
}
Expand Down Expand Up @@ -1774,12 +1783,14 @@ - (void)presentPopoverFromRect:(CGRect)aRect
_animated = aAnimated;
options = aOptions;

#if !defined(WY_APP_EXTENSIONS)
if (!_inView) {
_inView = [UIApplication sharedApplication].keyWindow.rootViewController.view;
if (CGRectIsEmpty(_rect)) {
_rect = CGRectMake((int)_inView.bounds.size.width / 2 - 5, (int)_inView.bounds.size.height / 2 - 5, 10, 10);
}
}
#endif

CGSize contentViewSize = self.popoverContentSize;

Expand Down Expand Up @@ -1986,7 +1997,7 @@ - (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated
- (CGAffineTransform)transformForArrowDirection:(WYPopoverArrowDirection)arrowDirection {
CGAffineTransform transform = _backgroundView.transform;

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
UIInterfaceOrientation orientation = WY_USER_INTERFACE_ORIENTATION;

CGSize containerViewSize = _backgroundView.frame.size;

Expand Down Expand Up @@ -2048,7 +2059,7 @@ - (void)setPopoverNavigationBarBackgroundImage {

- (void)positionPopover:(BOOL)aAnimated {
CGRect savedContainerFrame = _backgroundView.frame;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
UIInterfaceOrientation orientation = WY_USER_INTERFACE_ORIENTATION;
CGSize contentViewSize = self.popoverContentSize;
CGSize minContainerSize = WY_POPOVER_MIN_SIZE;

Expand Down Expand Up @@ -2090,7 +2101,7 @@ - (void)positionPopover:(BOOL)aAnimated {

viewFrame = [_inView convertRect:_rect toView:nil];

viewFrame = WYRectInWindowBounds(viewFrame, orientation);
viewFrame = WYRectInWindowBounds(_inView.window, viewFrame, orientation);

minX = _popoverLayoutMargins.left;
maxX = overlayWidth - _popoverLayoutMargins.right;
Expand Down Expand Up @@ -2341,7 +2352,7 @@ - (void)positionPopover:(BOOL)aAnimated {

containerFrame = _backgroundView.frame;

containerFrame.origin = WYPointRelativeToOrientation(containerOrigin, containerFrame.size, orientation);
containerFrame.origin = WYPointRelativeToOrientation(_backgroundView.window, containerOrigin, containerFrame.size, orientation);

if (aAnimated == YES && !self.implicitAnimationsDisabled) {
_backgroundView.frame = savedContainerFrame;
Expand Down Expand Up @@ -2637,10 +2648,10 @@ - (CGSize)sizeForRect:(CGRect)aRect
inView:(UIView *)aView
arrowHeight:(float)arrowHeight
arrowDirection:(WYPopoverArrowDirection)arrowDirection {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
UIInterfaceOrientation orientation = WY_USER_INTERFACE_ORIENTATION;

CGRect viewFrame = [aView convertRect:aRect toView:nil];
viewFrame = WYRectInWindowBounds(viewFrame, orientation);
viewFrame = WYRectInWindowBounds(aView.window, viewFrame, orientation);

float minX, maxX, minY, maxY = 0;

Expand Down Expand Up @@ -2728,6 +2739,7 @@ static BOOL compileUsingIOS8SDK() {
}

static float WYStatusBarHeight() {
#if !defined(WY_APP_EXTENSIONS)
if (compileUsingIOS8SDK() && [[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
return statusBarFrame.size.height;
Expand All @@ -2744,6 +2756,9 @@ static float WYStatusBarHeight() {

return statusBarHeight;
}
#else
return 0.0f;
#endif
}

static float WYInterfaceOrientationAngleOfOrientation(UIInterfaceOrientation orientation) {
Expand All @@ -2770,9 +2785,9 @@ static float WYInterfaceOrientationAngleOfOrientation(UIInterfaceOrientation ori
return angle;
}

static CGRect WYRectInWindowBounds(CGRect rect, UIInterfaceOrientation orientation) {
static CGRect WYRectInWindowBounds(UIWindow *window, CGRect rect, UIInterfaceOrientation orientation) {

UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIWindow *keyWindow = window;

float windowWidth = keyWindow.bounds.size.width;
float windowHeight = keyWindow.bounds.size.height;
Expand Down Expand Up @@ -2806,9 +2821,9 @@ static CGRect WYRectInWindowBounds(CGRect rect, UIInterfaceOrientation orientati
return result;
}

static CGPoint WYPointRelativeToOrientation(CGPoint origin, CGSize size, UIInterfaceOrientation orientation) {
static CGPoint WYPointRelativeToOrientation(UIWindow *window, CGPoint origin, CGSize size, UIInterfaceOrientation orientation) {

UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIWindow *keyWindow = window;

float windowWidth = keyWindow.bounds.size.width;
float windowHeight = keyWindow.bounds.size.height;
Expand Down