ios - Rotation support in custom transitions - Constraints or update frame on rotation? -


i creating 'semi-modal' transition displays content bottom of screen not fill whole screen.

the height of modal dependent on preferred content size of toviewcontroller (if preferred size larger container view capped @ height).

this working expected until comes rotation.

the current transition works using frames device rotated semimodal view displayed positioned incorrectly (see screenshots).

semimodal transition presented in portrait transition after rotation

it seems default containerview (part of transitioncontext) has w+h auto resizing mask. toviewcontroller has w+h.

what want transition height fixed, width flexible , ‘pinned’ bottom of container view.

this can achieved using constrains in transition e.g

// in animatetransition: uiview *toview = toviewcontroller.view; toview.translatesautoresizingmaskintoconstraints = no; // should transition altering this? [containerview addsubview:toview];  [containerview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-0-[toview]-0-|" options:nslayoutformatdirectionleadingtotrailing metrics:nil views:nsdictionaryofvariablebindings(toview)]];  [containerview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:[toview(height)]-0-|" options:nslayoutformatdirectionleadingtotrailing metrics:@{@"height" : @(endframe.size.height)} views:nsdictionaryofvariablebindings(toview)]]; 

but question allowed add constraints containerview? examples have seen frames have been used in transition.

alternatively, can update frame during rotation asking transition it’s preferred size given rotation. however, seems messy , means have keep reference transition, transition have keep reference container view , toview (although weak) , viewcontroller needs ask new frame during rotation.

// in vc presents semimodal view - (void)willanimaterotationtointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration {     [super willanimaterotationtointerfaceorientation:tointerfaceorientation duration:duration];     if (self.presentedviewcontroller && _tansitiondelegate) { // if showing vc presented using custom transition         [self updateviewcontrollerpresentedwithtransitionsframe];     } }  - (void)updateviewcontrollerpresentedwithtransitionsframe {     cgrect endframe = [_tansitiondelegate endframe]; // transition delegate asks transition new frame current orientation. calculated based on frame of transitions containerview , toviewcontrollers preferred size     self.presentedviewcontroller.view.frame = endframe; } 

both of these approaches seem work nice know recommended way this? or if missing specific transition rotation api :)

update

i tried expand on constraint approach make sure presented view not more 0.75 of height of it's parent (this done using frame calculation).

[containerview addconstraint:[nslayoutconstraint constraintwithitem:toview                                                           attribute:nslayoutattributeheight                                                           relatedby:nslayoutrelationlessthanorequal                                                              toitem:containerview                                                           attribute:nslayoutattributeheight                                                          multiplier:kdefaultmodalproportion                                                            constant:0]]; 

unfortunately causes unable simultaneously satisfy constraints error containerview using autoresizingmasks. looks can correctly implemented frames updated view controller during rotation?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -