Ios 加载/卸载子视图时设置中心位置重置

Ios 加载/卸载子视图时设置中心位置重置,ios,objective-c,position,subview,Ios,Objective C,Position,Subview,这一整天都快把我逼疯了!我是objective-c的相对初学者,请原谅我的错误 我想做的是在视图的屏幕上为一些按钮分配一个随机的x位置,这是我正在使用的代码: int screenwidth = ([UIScreen mainScreen].bounds.size.height - 100); [_Game0_Button1 setCenter:(CGPointMake(arc4random_uniform(screenwidth) + 50, _Game0_Button1.center.y))

这一整天都快把我逼疯了!我是objective-c的相对初学者,请原谅我的错误

我想做的是在视图的屏幕上为一些按钮分配一个随机的x位置,这是我正在使用的代码:

int screenwidth = ([UIScreen mainScreen].bounds.size.height - 100);
[_Game0_Button1 setCenter:(CGPointMake(arc4random_uniform(screenwidth) + 50, _Game0_Button1.center.y))];
虽然这可以正常工作,但当子视图加载或卸载时,指定的新位置将重置回其原始位置,例如:

[self addChildViewController: GamePausedVC];

GamePausedVC.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
GamePausedVC.delegate = self;
[self.view addSubview: GamePausedVC.view];
[GamePausedVC didMoveToParentViewController: self];

[GamePausedVC willMoveToParentViewController:nil];
[GamePausedVC.view removeFromSuperview];
[GamePausedVC removeFromParentViewController];
我做错了什么


谢谢

保留一个随机位置数组,并重置视图中的按钮位置将出现

是的,我想这是解决问题的一种方法。我真的想知道在加载/卸载子视图时重置位置是否正常。。即使在ViewDidDisplay中重置按钮位置也不能像加载子视图时那样工作。我不能延迟位置的更改,否则看起来会很糟糕,我也不能延迟子视图。我应该怎么做?尝试新的视图控制器调用
viewdilayoutsubviews