preferredContentSize does not shrink
I use UIPopoverController to popover a window. I use preferredContentSize to set the size. Then, I use Push a new view controller with larger size. When the child view pop up, I like to recover the window to original size. But seems not work.
I already put the self.preferredContentSize = myWindowSize; But it seems can not recover.
In iOS6 or before, I set the contentSizeForViewInPopover to CGSizeZero, then set the proper size. But on iOS7, it will make the popup disappear.
这为我解决了它:
override func viewDidAppear(animated: Bool)
{
navigationController?.preferredContentSize = preferredContentSize
super.viewDidAppear(animated)
}
The only solution I can think of is to dismiss your popover window and automatically present it again with the new size you want. I'm also having trouble for iOS 8 where the content size won't shrink in height. The width shrinks, but the height can only increase for me.
Have a look at
https://developer.apple.com/library/ios/documentation/uikit/reference/UIPopoverControllerDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIPopoverControllerDelegate/popoverController:willRepositionPopoverToRect:inView:
It might help you reposition the rect with the delegate protocol
Solution:
Ok, here's my solution. From the view controller where you present the popover controller, you can set up a delegate called something like "resetContentSize:(CGSize)size". eg in your presenting view controller's header file:
@protocol PopoverDelegate <NSObject>
- (void)resetContentSize:(CGSize)size
@end
in the implementation file where you present the popover controller, you can set the delegate
self.popoverController.delegate = self;
From your popover controller, you can add the PopoverDelegate in the header file
@property (nonatomic, weak) id<PopoverDelegate> popoverDelegate;
and call the delegate method in your implementation file:
[popoverDelegate resetContentSize:CGSizeMake(320.0f,205.0f)];
链接地址: http://www.djcxy.com/p/15994.html