preferredContentSize does not shrink

时光怂恿深爱的人放手 提交于 2021-01-27 04:21:30

问题


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.


回答1:


This solved it for me:

override func viewDidAppear(animated: Bool)
{
    navigationController?.preferredContentSize = preferredContentSize
    super.viewDidAppear(animated)
}



回答2:


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". e.g. 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)];



回答3:


Had the same issue. The solution for me was to set preferredContentSize on the navigationController, instead of self.

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.preferredContentSize = myControllerSize
}


来源:https://stackoverflow.com/questions/18941875/preferredcontentsize-does-not-shrink

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!