这让我整天发疯!我是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];
我究竟做错了什么?
谢谢!