Question

How to set center of the modalview controller to its center of self.view or Appdelegate window.I have sample code.The following code is presenting modalview at the right corner of the screen not at the center of the screen.
   MaterialDetailsViewController *materialDetails =[[MaterialDetailsViewController alloc]initWithNibName:NSLocalizedString(@"MaterialDetailsViewController",nil) bundle:nil];
      materialDetails.view.frame = CGRectMake(0, 0, 750, 650);
      materialDetails.modalPresentationStyle = UIModalPresentationFormSheet;
      materialDetails.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;  //transition shouldn't matter
      [self presentViewController:materialDetails animated:YES completion:nil];
     materialDetails.view.superview.frame = CGRectMake(self.view.superview.center.x - (750/2),
                                                       self.view.superview.center.y - (650/2),
                                                        750,650);
I tried to set the modalview frame center to self.view.center in MaterialDetailsViewController class like below
AppDelegate *delegate = [AppDelegate sharedInstance];
self.view.center = delegate.window.center;

But it doesn't fit to the center of the screen.I can try out this with Popovercontroller I can best do with that but i couldn't manage with modalview controller.I think this post will be helpful for those who are trying hard to set the frame for modalview.

Was it helpful?

Solution

Add to your MaterialDetailsViewController

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 750, 650);
}

iOS 5+

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top