@@ -1511,7 +1511,11 @@ - (CGSize)popoverContentSize
15111511
15121512 if (CGSizeEqualToSize (result, CGSizeZero))
15131513 {
1514- result = CGSizeMake (320 , 1100 );
1514+ CGSize windowSize = [[UIApplication sharedApplication ] keyWindow ].bounds .size ;
1515+
1516+ UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
1517+
1518+ result = CGSizeMake (320 , UIDeviceOrientationIsLandscape (orientation) ? windowSize.width : windowSize.height );
15151519 }
15161520
15171521 return result;
@@ -1555,7 +1559,7 @@ - (void)setPopoverContentSize:(CGSize)size
15551559#pragma clang diagnostic pop
15561560 }
15571561
1558- [self positionPopover ];
1562+ [self positionPopover: NO ];
15591563}
15601564
15611565- (void )presentPopoverFromRect : (CGRect)aRect
@@ -1666,7 +1670,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect
16661670 overlayView.backgroundColor = containerView.overlayColor ;
16671671 }
16681672
1669- [self positionPopover ];
1673+ [self positionPopover: NO ];
16701674
16711675 [self setPopoverNavigationBarBackgroundImage ];
16721676
@@ -1942,8 +1946,10 @@ - (void)setPopoverNavigationBarBackgroundImage
19421946 }
19431947}
19441948
1945- - (void )positionPopover
1949+ - (void )positionPopover : ( BOOL ) aAnimated
19461950{
1951+ CGRect savedContainerFrame = containerView.frame ;
1952+
19471953 UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
19481954
19491955 CGSize contentViewSize = self.popoverContentSize ;
@@ -2207,6 +2213,8 @@ - (void)positionPopover
22072213
22082214 containerFrame = CGRectIntegral (containerFrame);
22092215
2216+ containerView.frame = containerFrame;
2217+
22102218 containerView.wantsDefaultContentAppearance = wantsDefaultContentAppearance;
22112219
22122220 [containerView setViewController: viewController];
@@ -2235,7 +2243,18 @@ - (void)positionPopover
22352243
22362244 containerFrame.origin = WYPointRelativeToOrientation (containerOrigin, containerFrame.size , orientation);
22372245
2238- containerView.frame = containerFrame;
2246+ if (aAnimated == YES ) {
2247+ containerView.frame = savedContainerFrame;
2248+ __weak __typeof__ (self) weakSelf = self;
2249+ [UIView animateWithDuration: 0 .10f animations: ^{
2250+ __typeof__ (self) strongSelf = weakSelf;
2251+ strongSelf->containerView .frame = containerFrame;
2252+ }];
2253+ } else {
2254+ containerView.frame = containerFrame;
2255+ }
2256+
2257+ WY_LOG (@" popoverContainerView.frame = %@ " , NSStringFromCGRect(containerView.frame ));
22392258}
22402259
22412260- (void )dismissPopoverAnimated : (BOOL )aAnimated
@@ -2420,7 +2439,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
24202439 if ([keyPath isEqualToString: NSStringFromSelector (@selector (preferredContentSize ))]
24212440 || [keyPath isEqualToString: NSStringFromSelector (@selector (contentSizeForViewInPopover ))])
24222441 {
2423- [self positionPopover ];
2442+ [self positionPopover: YES ];
24242443 }
24252444 }
24262445}
@@ -2806,8 +2825,8 @@ - (void)didChangeDeviceOrientation:(NSNotification *)notification
28062825 }
28072826 }
28082827
2809- [self positionPopover ];
2810- [containerView setNeedsDisplay ];
2828+ [self positionPopover: NO ];
2829+ // [containerView setNeedsDisplay];
28112830}
28122831
28132832- (void )keyboardWillShow : (NSNotification *)notification
@@ -2820,15 +2839,15 @@ - (void)keyboardWillShow:(NSNotification *)notification
28202839 WY_LOG (@" orientation = %@ " , WYStringFromOrientation (orientation));
28212840 WY_LOG (@" keyboardRect = %@ " , NSStringFromCGRect(keyboardRect));
28222841
2823- [self positionPopover ];
2824- [containerView setNeedsDisplay ];
2842+ [self positionPopover: YES ];
2843+ // [containerView setNeedsDisplay];
28252844}
28262845
28272846- (void )keyboardWillHide : (NSNotification *)notification
28282847{
28292848 keyboardRect = CGRectZero;
2830- [self positionPopover ];
2831- [containerView setNeedsDisplay ];
2849+ [self positionPopover: YES ];
2850+ // [containerView setNeedsDisplay];
28322851}
28332852
28342853#pragma mark Memory management
0 commit comments