我现在正在设计ipad应用程序的界面,我想在rootview的中心放置一个视图。我的代码是:

CGRect ret = CGRectMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds), bounds.size.width / 2,     bounds.size.height / 2);

newViewController.view.frame = ret;
newViewController.view.center = self.view.center;

self.newViewController = newViewController;
[self.view addSubview:_newViewController.view];


结果是我想要的如下:



但是当我旋转到风景时,它变成:



我想知道为什么它不能像我设置的那样居中放置,如何使它起作用?谢谢!

最佳答案

youView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|
                                                 UIViewAutoresizingFlexibleBottomMargin|
                                                 UIViewAutoresizingFlexibleLeftMargin|
                                                 UIViewAutoresizingFlexibleRightMargin;
youView.autoresizesSubviews= YES;

10-06 09:00