Resize ModalViewController and position it at center in iOS 7

百般思念 提交于 2019-12-05 06:20:13

For iOS 7 try this:

[self.navigationController presentViewController:navigationController animated:YES completion:^{
    //Make the modal bigger than normal
    navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
}];

The animation will look ugly so I would recommend adding an animation to improve it:

[self.navigationController presentViewController:navigationController animated:YES completion:^{
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        //Make the modal bigger than normal
        navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
    } completion:^(BOOL finished) {
    }];
}];

Also remember that you will need to set the frame of the navigationControllers view in the viewDidAppear for the content to be the correct size.

rfrittelli

You need to center the frame something like this should work (I haven't tested).

CGRect appFrame = [UIScreen mainScreen].applicationFrame;
CGRect modalFrame = m_helpQA.view.superview.frame;
modalFrame.size = CGSizeMake(350.f, 250.f);
modalFrame.origin.x = appFrame.size.width/2.0f - modalFrame.size.width/2.0f;
modalFrame.origin.y = appFrame.size.height/2.0f - modalFrame.size.height/2.0f;
m_helpQA.view.superview.frame = modalFrame;

Updated Code to correct typo

Try the following:

UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
...

[self presentViewController:vc animated:NO completion:^{
    vc.view.superview.center = self.view.window.center;
}];

// resize modal view
infoModalViewController.view.superview.bounds = CGRectMake(0, 0, newWidth, newHeight);

I had to set the center (in this case to the center of the window but you can use the center of your parent view controller as well) in the completition block to get it working properly. Switch to animation:No because otherwise it will look ugly :-)

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