我面临一个非常烦人的问题。
下面是上下文:我有一个“矩形”视图,它是主视图的子视图。
我想做的很简单,当我点击一个按钮时,我希望“矩形”视图在x轴方向上移动,以便消失。然后我添加一个新的子视图,并将其平移以取代先前的“矩形”视图。
这很好用,除了如果我再次按下该按钮,动画将从屏幕外开始,就像CGAffineTransformMakeTranslation没有改变我的新“矩形”视图的框架一样。
以下是代码:
UIView *rectangleView = [detailView viewWithTag:4]; //the actual frame is (20.0, 30.0, 884.0, 600.0)
[UIView animateWithDuration:0.5 animations:^{
[rectangleView setTransform:CGAffineTransformMakeTranslation(-1000, 0)];
} completion:^(BOOL finished) {
[rectangleView removeFromSuperview];
UIView *otherView = [[UIView alloc] initWithFrame:CGRectMake(1020.0, 30.0, 884.0, 600.0)];
[otherView setBackgroundColor:[UIColor purpleColor]];
[otherView setTag:4];
[detailView addSubview:otherView];
[UIView animateWithDuration:0.5 animations:^{
[otherView setTransform:CGAffineTransformMakeTranslation(-1000, 0)];
} completion:^(BOOL finished) {
[otherView release];
}];
}];