@@ -1356,7 +1356,7 @@ - (WYPopoverArrowDirection)arrowDirectionForRect:(CGRect)aRect
13561356 permittedArrowDirections : (WYPopoverArrowDirection)arrowDirections ;
13571357
13581358- (CGSize)sizeForRect : (CGRect)aRect
1359- inView : (UIView*)aView
1359+ inView : (UIView *)aView
13601360 arrowHeight : (CGFloat)arrowHeight
13611361 arrowDirection : (WYPopoverArrowDirection)arrowDirection ;
13621362
@@ -1781,7 +1781,7 @@ - (CGAffineTransform)transformForArrowDirection:(WYPopoverArrowDirection)arrowDi
17811781 CGAffineTransform transform = containerView.transform ;
17821782
17831783 UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
1784-
1784+
17851785 CGSize containerViewSize = containerView.frame .size ;
17861786
17871787 if (containerView.arrowHeight > 0 )
@@ -1890,10 +1890,12 @@ - (void)positionPopover
18901890
18911891 // Position of the popover
18921892 //
1893+ CGFloat keyboardHeight = UIInterfaceOrientationIsPortrait (orientation) ? keyboardRect.size .height : keyboardRect.size .width ;
1894+
18931895 minX -= containerView.outerShadowInsets .left ;
18941896 maxX += containerView.outerShadowInsets .right ;
18951897 minY -= containerView.outerShadowInsets .top ;
1896- maxY += containerView.outerShadowInsets .bottom - (( UIInterfaceOrientationIsPortrait (orientation)) ? keyboardRect. size . height : keyboardRect. size . width ) ;
1898+ maxY += containerView.outerShadowInsets .bottom - keyboardHeight ;
18971899
18981900 if (arrowDirection == WYPopoverArrowDirectionDown)
18991901 {
@@ -2120,6 +2122,22 @@ - (void)positionPopover
21202122
21212123 [containerView setViewController: viewController];
21222124
2125+ // keyboard support
2126+ //
2127+ if (keyboardHeight > 0 ) {
2128+
2129+ CGFloat keyboardY = UIInterfaceOrientationIsPortrait (orientation) ? keyboardRect.origin .y : keyboardRect.origin .x ;
2130+
2131+ if (containerFrame.origin .y + containerFrame.size .height > keyboardY) {
2132+
2133+ containerFrame.origin .y -= (containerFrame.origin .y + containerFrame.size .height - keyboardY);
2134+
2135+ if (containerFrame.origin .y < minY) {
2136+ containerFrame.origin .y = minY;
2137+ }
2138+ }
2139+ }
2140+
21232141 CGPoint containerOrigin = containerFrame.origin ;
21242142
21252143 containerView.transform = CGAffineTransformMakeRotation (WYInterfaceOrientationAngleOfOrientation (orientation));
@@ -2128,6 +2146,8 @@ - (void)positionPopover
21282146
21292147 containerFrame.origin = WYPointRelativeToOrientation (containerOrigin, containerFrame.size , orientation);
21302148
2149+
2150+
21312151 containerView.frame = containerFrame;
21322152}
21332153
@@ -2457,13 +2477,16 @@ - (CGSize)sizeForRect:(CGRect)aRect
24572477
24582478 CGFloat minX, maxX, minY, maxY = 0 ;
24592479
2480+ CGFloat keyboardHeight = UIInterfaceOrientationIsPortrait (orientation) ? keyboardRect.size .height : keyboardRect.size .width ;
2481+
24602482 CGFloat overlayWidth = UIInterfaceOrientationIsPortrait (orientation) ? overlayView.bounds .size .width : overlayView.bounds .size .height ;
2483+
24612484 CGFloat overlayHeight = UIInterfaceOrientationIsPortrait (orientation) ? overlayView.bounds .size .height : overlayView.bounds .size .width ;
24622485
24632486 minX = popoverLayoutMargins.left ;
24642487 maxX = overlayWidth - popoverLayoutMargins.right ;
24652488 minY = WYStatusBarHeight () + popoverLayoutMargins.top ;
2466- maxY = overlayHeight - popoverLayoutMargins.bottom ;
2489+ maxY = overlayHeight - popoverLayoutMargins.bottom - keyboardHeight ;
24672490
24682491 CGSize result = CGSizeZero;
24692492
@@ -2681,6 +2704,13 @@ - (void)keyboardWillShow:(NSNotification *)notification
26812704{
26822705 NSDictionary *info = [notification userInfo ];
26832706 keyboardRect = [[info objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue ];
2707+
2708+ UIInterfaceOrientation orientation = [[UIApplication sharedApplication ] statusBarOrientation ];
2709+
2710+ WY_LOG (@" orientation = %@ " , WYStringFromOrientation (orientation));
2711+
2712+ WY_LOG (@" keyboardRect = %@ " , NSStringFromCGRect(keyboardRect));
2713+
26842714 [self positionPopover ];
26852715 [containerView setNeedsDisplay ];
26862716}
0 commit comments