m1entus / MZFormSheetPresentationController

MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.
MIT License
973 stars 146 forks source link

Change content size for second view controller from first view controller #96

Closed Joker666 closed 8 years ago

Joker666 commented 8 years ago

I see in the first demo image, two view controllers have different content size. I presented my first view controller with formSheetPresentationController, but I need to change the content size for the second view controller that I push from first view controller. The update for 2.x changelog says

but it's not documented anywhere how to achieve that. It'll be very helpful if you document that.

m1entus commented 8 years ago

@phatmann Could you add some info about it?

eliburke commented 8 years ago

@Joker666 I was able to puzzle this out. You need to add <MZFormSheetPresentationContentSizing> to each of your view controllers that you display in the form sheet and then implement the protocol:

- (BOOL)shouldUseContentViewFrameForPresentationController:(MZFormSheetPresentationController *)presentationController {
    return YES;
}

- (CGRect)contentViewFrameForPresentationController:(MZFormSheetPresentationController *)presentationController currentFrame:(CGRect)currentFrame {
    currentFrame.size.width = _modalContentSize.width;
    currentFrame.size.height = _modalContentSize.height;
    return currentFrame;
}

_modalContentSize is my own property-- you can return a fixed value or whatever.

Joker666 commented 8 years ago

@eliburke tried it, didn't seem to work for me.

eliburke commented 8 years ago

Hmm... maybe you need to use a MZFormSheetContentSizingNavigationController? Sorry I fiddled around with this a bit but didn't document which steps were part of the solution. Try putting breakpoints into shouldUseContentViewFrameForPresentationController and make sure they are being called. Take a look at MZFormSheetPresentationController.m at modifiedContentViewFrameForFrame which is where your view controllers' size is checked. Another possibility: all of your view controllers must implement the protocol, not just those that are pushed from the primary.

phatmann commented 8 years ago

From the README:

formSheetController.presentationController?.contentViewSize = CGSizeMake(250, 250)  // or pass in UILayoutFittingCompressedSize to size automatically with auto-layout

So pass UILayoutFittingCompressedSize into contentViewSize and auto-layout will be used to size the dialog.

Joker666 commented 8 years ago

UILayoutFittingCompressedSize doesn't work, breaks the layout, it needs height externally.

phatmann commented 8 years ago

When I first tried this option, my height did not work either. You have to make sure all of your contentHugging and contentCompressed priorities are set correctly, and you need to make sure that you have at least one view anchored to the bottom. If you get constraint conflicts before the sizing takes place, you might have to reduce the bottom constraint to 900 priority.