ios 8 change the size of presented/modal view controller

前端 未结 3 701
执念已碎
执念已碎 2020-12-14 04:27

In ios 7 and before, I was updating the bounds of presentedViewController.view.superview to custom the size of presented view controller, but it seems this would not be the

相关标签:
3条回答
  • 2020-12-14 04:48

    I guess the following is easier and it works in iOS 8:

    self.myViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    self.myViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    
    //This will be the size you want
    self.myViewController.preferredContentSize = CGSizeMake(822, 549);
    
    [self presentViewController:self.myViewController animated:YES completion:nil];
    
    0 讨论(0)
  • 2020-12-14 04:54

    In case anyone runs into this later, here is how I solve it.

    Subclass the UIPresentationController and return the frame in frameOfPresentedViewInContainerView. Feed this into the transitioningDelegate that you create for the presentedViewController.

    Or, you may set the final frame for the presentedView in the animateTransition:, which belongs to the animator object you created for transitioningDelegate. However, this is the old iOS 7 way of doing it. Since Apple introduce UIPresentationController, any size/frame changes should be done there instead, which is the previous method I mentioned.

    Here are some extra information that may not be directly related to solving the problem.

    For those of you who never got your hands on the apple view controller transition api, just like me before, here are the steps.

    1. Create YourTransitioningDelegate, which conforms UIViewControllerTransitioningDelegate. In here, generally three things need to be set, PresentationController, PresentedAnimationController, DismissedAnimationController.

    2. Create YourTransitionAnimator, which conforms UIViewControllerAnimatedTransitioning. Here, two functions need to be override, transitionDuration and animateTransition(This is where all the animation happens, adding/removing and animating the presentedView. Make you call completeTransition on transitionContext to end the animation).

    3. Subclass UIPresentationController. Depends on each individual needs, you may do a ton of things here. I just added a dimmingView and changed the frame of presentedViewController.

    4. Finally, hook things up before presenting the view controller, which is changing the modalPresentationStyle to be custom and setting the transitioning delegate.

    Things I found really helpful, two 2014 WWDC videos("View controllers advancements" and "A look inside presentation controllers") and the sample project from Apple(LookInside-photoEditingApp).

    0 讨论(0)
  • 2020-12-14 05:09

    Instead of subclassing you can use the preferredContentSize property

    - (void)viewDidLoad {
       [super viewDidLoad];
    
       self.preferredContentSize = CGSizeMake((self.view.frame.size.width / 100) * 65, (self.view.frame.size.height / 100) * 65);
    }
    
    0 讨论(0)
提交回复
热议问题