当作为表单表示时,难以将视图控制器置于中心位置

时间:2013-03-17 04:08:30

标签: iphone ios objective-c ipad uiviewcontroller

我正在尝试呈现一个视图控制器,其表示样式设置为表单。但是,当视图控制器出现时,它位于屏幕右侧,而不是位于中心。我不确定为什么会发生这种情况,或者我应该做什么。所有这些坐标都是正确的!

CGSize size = CGSizeMake(650, 550);

//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:nav animated:YES];

nav.view.superview.frame = CGRectMake(0, 0, size.width, size.height);
nav.view.superview.center = self.view.center;

enter image description here

1 个答案:

答案 0 :(得分:1)

似乎无论何时我删除最后两行,我都会得到我认为你正在寻找的行为。

CGSize size = CGSizeMake(650, 550);

//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:nav animated:YES];

我不确定你究竟用这两行做了什么,但没有它们,视图就会居中。