我有一个自定义视图,我用动画呈现弹跳效果。现在,我希望它以类似于收缩然后消失的方式消失。
下面这段代码以弹跳效果呈现我的视图工作正常:
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 是一样的。