我有一个自定义视图,我提供动画给出弹跳效果。现在,我希望它以类似缩小的方式消失然后消失。
下面的一段代码以弹跳效果呈现我的视图正常工作:
self.componentDetailController.view.center = iGestureRecognizer.view.center;
self.componentDetailController.view.alpha = 0.0;
self.componentDetailController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:(0.2) animations:^{
self.componentDetailController.view.center = CGPointMake(kScreenWidth / 2, kScreenHeight / 2);
self.componentDetailController.view.alpha = 0.5;
self.componentDetailController.view.transform = CGAffineTransformMakeScale(1.05, 1.05);
} completion:^(BOOL iFinished) {
[UIView animateWithDuration:(0.1) animations:^{
self.componentDetailController.view.alpha = 0.90;
self.componentDetailController.view.center = CGPointMake(kScreenWidth / 2, kScreenHeight / 2);
self.componentDetailController.view.transform = CGAffineTransformMakeScale(0.98, 0.98);
} completion:^(BOOL iFinished) {
self.componentDetailController.view.alpha = 1.0;
self.componentDetailController.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.componentDetailController.view.transform = CGAffineTransformIdentity;
}];
}];
我已经编写了下面的代码来缩小和忽略不起作用的视图。它将视图稍微带到前面,但不会忽略它。任何线索有什么问题:
- (void)cancelButtonPressed {
self.componentDetailController.view.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:(0.1) animations:^{
self.componentDetailController.view.alpha = 1.0;
self.componentDetailController.view.transform = CGAffineTransformMakeScale(1.05, 1.05);
} completion:^(BOOL iFinished) {
[UIView animateWithDuration:(0.4) animations:^{
self.componentDetailController.view.center = self.tappedComponentView.center;
self.componentDetailController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);
self.componentDetailController.view.backgroundColor = [UIColor clearColor];
self.componentDetailController.view.alpha = 0.0;
} completion:^(BOOL iFinished) {
[self.componentDetailController.view removeFromSuperview];
}];
}];
self.componentDetailController = nil;
[self enableBackView];
}
这里,self.tappedComponentView.center与self.tappedComponentView.center相同。
答案 0 :(得分:5)
+animateWithDuration:animations:completion:
调用会立即返回,因此第二个动画运行后,self.componentDetailController
即nil
,所有后续的视图转换调用都无处可寻。将self.componentDetailController.view
存储到自己的变量中,并在动画块中引用它。 E.g:
UIView *detailView = self.componentDetailController.view;
detailView.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.1 animations:^{
detailView.alpha = 1;
// …
}];
self.componentDetailController = nil;