Skip to content

Commit 58363cd

Browse files
fix issue #26
1 parent 2c36881 commit 58363cd

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

WYPopoverController/WYPopoverController.m

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ - (IBAction)showpopover:(id)sender
8888
WYSettingsViewController *settingsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"WYSettingsViewController"];
8989

9090
if ([settingsViewController respondsToSelector:@selector(setPreferredContentSize:)]) {
91-
settingsViewController.preferredContentSize = CGSizeMake(300, 200); // iOS 7
91+
settingsViewController.preferredContentSize = CGSizeMake(320, 320); // iOS 7
9292
}
9393
else {
94-
settingsViewController.contentSizeForViewInPopover = CGSizeMake(300, 200); // iOS < 7
94+
settingsViewController.contentSizeForViewInPopover = CGSizeMake(320, 320); // iOS < 7
9595
}
9696

9797
settingsViewController.title = @"Settings";

demos/Demo/WYPopoverDemo/WYAnotherViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
2525

2626
- (IBAction)resizeme:(id)sender
2727
{
28-
self.preferredContentSize = CGSizeMake(300, 300);
28+
self.preferredContentSize = CGSizeMake(360, 220);
2929
}
3030

3131
- (void)viewDidLoad

0 commit comments

Comments
 (0)