iOS — how do you control the size of a modal view controller?

后端 未结 3 1020
忘掉有多难
忘掉有多难 2020-12-07 17:32

I am presenting a modal view controller. If it matters, it is scrolling up from the bottom. How can I control what portion of the screen it occupies?

EDIT: I have

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 17:51

    I would add to @dsaw's answer that the superview of the modal view does not seem to rotate its coordinate system in landscape mode. Here is the code that I used in my own app:

    MyViewController* modalVC = [[MyViewController alloc] init];        
    modalVC.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:modalVC animated:NO];
    CGRect r = CGRectMake(self.view.bounds.size.width/2 - 236,
                          self.view.bounds.size.height/2 - 130,
                          472, 260);
    r = [self.view convertRect:r toView:modalVC.view.superview.superview];
    modalVC.view.superview.frame = r;
    

    While the superview may not rotate itself with the iPad, it does seem to do the right thing and keep the modal view centered if I rotate the iPad after showing the modal view.

提交回复
热议问题