0

我有一个试图以模态方式呈现的视图控制器。我需要将其移动到屏幕上的特定位置。下面的代码在纵向上可以正常工作,但在横向上,无论我将中心设置在哪一点,视图都不会重新定位。如果我使用 pcvc.landscapeView.center 而不是 pcvc.landscapeView 视图会重新定位,但灰色框仍保留在视图的原始位置,并且我无法与视图交互。

在横向时,我需要如何区别对待视图控制器?

PostCommentViewController *pcvc = [[PostCommentViewController alloc] initWithNibName:@"PostCommentViewController" bundle:nil];
pcvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
pcvc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:(UIViewController *)pcvc animated:YES completion:nil];
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
    pcvc.portraitView.superview.frame = CGRectMake(0, 0, 750, 143);
    pcvc.portraitView.superview.center = CGPointMake(384, 680);
}
else
{
    pcvc.landscapeView.superview.frame = CGRectMake(0, 0, 683, 300);
    pcvc.landscapeView.superview.center = CGPointMake(500, 60);
}
4

1 回答 1

0

这段代码我真的无能为力。您正在加载一个名为PostCommentViewController That xib 文件的 xib 文件有 2 个视图portraitViewlandscapeView 并且您尝试移动超级视图,以便包含portraitView和的视图landscapeView

我不明白,但作为一个快速修复,你可以为不同的布局制作不同的 xib。同样,我没有您的视图控制器层次结构,因此很难提供帮助。

在 didrotate 中调用它

-(void)changeOrientation {
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
        [[NSBundle mainBundle] loadNibNamed:@"Portrait" owner:self options:nil];
    }
    else {
        [[NSBundle mainBundle] loadNibNamed:@"Landscape" owner:self options:nil];
    }

}
于 2013-11-18T11:38:30.940 回答