0

我有最奇怪的错误。我在情节提要中有两个 UIImageView,一个大的,我们称之为 A,一个小的,B。我在视图控制器中为小一个的位置设置动画,效果很好。

但是:当我尝试替换 A 的背景图像时,突然间,B 捕捉到它在情节提要中的原始位置并且它不会让步。事情是这样的:我进行了测试,我注意到如果 A 不超过某个宽度,B 可以移动,并且不会弹回。我尝试在延迟后更改 A 的图像,在视图控制器中使用 [self performSelector:] 超时,但就在我更改图像时,B 突然回到它在情节提要中的位置。我不知道这怎么可能,尽管它对我来说确实像是一个记忆问题。

这是我的动画代码:

CGRect newFrame = self.B.frame;
newFrame.origin.x = newX; // defined earlier

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:.1];

[[[UIAlertView alloc] initWithTitle:@"Moving" message:[NSString stringWithFormat:@"Moving from %g to %d!", self.B.frame.origin.x, newX] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

self.B.frame = newFrame;

[UIView commitAnimations];
4

1 回答 1

2

当 A 较大时,您在两个图像视图之间存在无意的约束。

于 2013-04-13T00:36:38.780 回答