Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize ModalViewController and position it at center in iOS 7

I am trying to show a modalView on an iPad by reducing its width and height, but the problem is that it is not center-aligned. In iOS 6 it used to work fine, but in iOS 7 it is not center aligned.

Below is my code:

 m_helpQA = [[HelpQAViewController alloc]init];

 m_helpQA.modalPresentationStyle = UIModalPresentationFormSheet;      

 [self presentViewController:m_helpQA animated:YES completion:NULL];
 m_helpQA.view.superview.bounds = CGRectMake(0, 0, 350, 250);//Dimensions of ModalView.

presently I am getting it this way

enter image description here

like image 798
Ranjit Avatar asked Oct 21 '13 11:10

Ranjit


1 Answers

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.

like image 73
Eeshwar Avatar answered Oct 04 '22 02:10

Eeshwar