Closed acegreen closed 8 years ago
Check examples there is an answer for that...
@m1entus Dziękuję...But can you be a little more specific. I didn't catch anything
EDIT: prior to using MZFormSheetPresentationController I was presenting the VC modally as a form sheet and setting my .preferredContentSize in prepareForSegue. This would then adapt with rotation.
Are we expected to handle rotation manually? Would it make sense for MZFormSheetPresentationController to recalculate contentViewSize on rotation?
I'm still familiarizing myself with the library and I'm looking at this
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.dimmingView.frame = self.containerView.bounds;
[self setupFormSheetViewControllerFrame];
} completion:nil];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
Things get a little confusing within formSheetViewControllerFrame()
Nix all that.. got it working. I'll list it for future reference:
public func shouldUseContentViewFrame(for presentationController: MZFormSheetPresentationController!) -> Bool {
return true
}
func contentViewFrame(for presentationController: MZFormSheetPresentationController!, currentFrame: CGRect) -> CGRect {
var currentFrame = currentFrame
currentFrame.size.width = Constants.application.keyWindow!.bounds.size.width
return currentFrame
}
In my case, I wanted the width to always be my windows width.
👍
Because reasons, I display a UIImagePickerController in a full screen modal form sheet. Something about this configuration causes problems during autorotation-- the imagePicker detects rotation, but the bounds do not change from portrait to landscape and vice versa.
In case anyone needs to fix the bounds of a system view controller, it can be done in a category without subclassing:
// category to add content sizing behavior
@interface UIImagePickerController (modalRotate) <MZFormSheetPresentationContentSizing>
@end
@implementation UIImagePickerController (modalRotate)
- (BOOL)shouldUseContentViewFrameForPresentationController:(MZFormSheetPresentationController *)presentationController {
return YES;
}
- (CGRect)contentViewFrameForPresentationController:(MZFormSheetPresentationController *)presentationController currentFrame:(CGRect)currentFrame {
return [UIScreen mainScreen].bounds;
}
@end
Thank you @acegreen!
FYI:
You implement the delegate functions in the UIViewController which conforms to MZFormSheetPresentationContentSizing
. I did something like this:
import MZFormSheetPresentationController
...
class CustomUIViewController: UIViewController {
...
}
extension CustomUIViewController: MZFormSheetPresentationContentSizing {
func shouldUseContentViewFrame(for presentationController: MZFormSheetPresentationController!) -> Bool {
return true
}
func contentViewFrame(for presentationController: MZFormSheetPresentationController!, currentFrame: CGRect) -> CGRect {
var currentFrame = currentFrame
currentFrame.size.width = Constants.application.keyWindow!.bounds.size.width
return currentFrame
}
}
Currently I have my contentViewSize setup as such
presentationSegue.formSheetPresentationController.presentationController?.contentViewSize = CGSize(width: self.view.bounds.size.width, height: 450)
I would like that to hold true while rotating the size. So my view is always full width.
Thanks in advance