1

我正在尝试制作一个有 3 个按钮的简单应用程序。当用户点击任何按钮时,他们会被动画(移动)到他们的新位置!所有这一切都来自这段代码:

[UIView animateWithDuration:1.2
                  delay:0.1
                options: UIViewAnimationCurveEaseOut
             animations:^
 {
 //Moving the Sum (UIButton which will move through this animation)
 CGRect frame =  Sum.frame;
 frame.origin.y = -20;
 frame.origin.x = (-120);
 Sum.frame = frame;
 .....
....
 }
             completion:^(BOOL finished)
  {
 NSLog(@"Completed");
//adding subview after the animation is complete! newView is an example!
[self.view addSubview:newView];}];

问题是,一旦我将子视图添加到主视图,所有按钮都会回到原来的位置!意味着他们没有被永久移动..我该如何解决这个问题?请帮助伙计们!

4

2 回答 2

1

添加视图时会发生什么?执行布局。你可能犯了两个错误

  1. 您正在使用自动布局。

    如果您使用自动布局,则不建议直接更改框架,并且重新布局将使用当前约束将视图更新到其原始位置。

  2. 您在或layoutSubviews中设置框架位置。viewWillLayoutviewDidLayout

    检查您设置原始位置的位置。该方法可以多次调用吗?

于 2013-09-19T08:28:59.127 回答
0

您已保存新框架的 X、Y 位置,然后通过编码设置此框架。

于 2013-09-19T07:49:43.327 回答