diff --git a/WYPopoverController.podspec b/WYPopoverController.podspec index 9e246c35..1721199b 100644 --- a/WYPopoverController.podspec +++ b/WYPopoverController.podspec @@ -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 diff --git a/WYPopoverController/WYPopoverController.m b/WYPopoverController/WYPopoverController.m index 95b738b6..50a49f11 100644 --- a/WYPopoverController/WYPopoverController.m +++ b/WYPopoverController/WYPopoverController.m @@ -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 @@ -1686,6 +1693,7 @@ - (CGSize)topViewControllerContentSize { #pragma clang diagnostic pop } +#if !defined(WY_APP_EXTENSIONS) if (CGSizeEqualToSize(result, CGSizeZero)) { CGSize windowSize = [[UIApplication sharedApplication] keyWindow].bounds.size; @@ -1693,6 +1701,7 @@ - (CGSize)topViewControllerContentSize { result = CGSizeMake(UIInterfaceOrientationIsPortrait(orientation) ? windowSize.width : windowSize.height, UIInterfaceOrientationIsLandscape(orientation) ? windowSize.width : windowSize.height); } +#endif return result; } @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -2744,6 +2756,9 @@ static float WYStatusBarHeight() { return statusBarHeight; } +#else + return 0.0f; +#endif } static float WYInterfaceOrientationAngleOfOrientation(UIInterfaceOrientation orientation) { @@ -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; @@ -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;