0

所以我想添加一个宽度为 450 和屏幕高度的 UIViewController,所以如果它是纵向的,那么高度是 1024,如果是横向,那么高度是 768。这个视图控制器,称为 ProfileViewController 有一个设置为 450 和1024. 自动调整大小设置为具有灵活高度。

 profViewController = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil];
            self.profileViewController_ = profViewController;
            [profViewController release];

因此,在 ProfileViewController 中,我还初始化了另一个名为 FeedsViewController 的视图控制器。现在的问题是,在 profViewController viewDidLoad 中,无论方向如何,高度总是设置为 1024。我怎样才能让它适应我的方向?我已经尝试设置 profViewController 的边界,但是这个更改会在 viewDidLoad 之后反映出来。

4

4 回答 4

0

要找到高度和宽度,试试这个

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
于 2012-07-20T04:35:09.083 回答
0

覆盖 profViewController 的以下方法

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, 450, 1024);

}
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, 450, 768);
    }
}
于 2012-07-20T05:24:11.893 回答
0

如果您以与在 NIB 中FeedsViewController设置视图框架相同的方式设置视图框架,则应该会自动正确调整大小。ProfileViewController也就是说,你给它一个你想要的相对于外部视图的初始大小,然后让系统的自动调整大小行为从那里获取东西。

在里面尝试这样ProfileViewController的事情viewDidLoad

// create and init self.feedsViewController
// ...

CGRect b = self.view.bounds;
self.feedsViewController.view.frame = CGRectMake((b.size.width - 450) / 2, 0, 450, b.size.height);
self.feedsViewController.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
于 2012-07-20T14:02:47.867 回答
0

如果你想改变你的 tableview 框架,你应该在viewDidAppear:而不是viewDidLoad:.

于 2012-07-21T07:46:13.780 回答