0
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; 

但它不適合屏幕的中心。我可以用Popovercontroller試試這個,我可以做到最好,但是我無法使用modalview控制器進行管理。我認爲這篇文章對那些幫助很大誰正在努力爲modalview設置框架。如何設置Modalview控制器的中心。是否有我能找到的解決方案?

回答

0

添加到您的MaterialDetailsViewController

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

iOS 5以上

相關問題