I have a custom view which I present with animation giving a bouncing effect. Now, I want it to disappear in the similar fashion like shrink and then disappear.
The below piece of code to present my view with a bouncing effect is working fine:
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;
}];
}];
I have written the below piece of code to shrink and dismiss the view which is not working. It brings the view to the front a little but then does not dismiss it. Any clue what is wrong here:
- (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];
}
Here, self.tappedComponentView.center is same as self.tappedComponentView.center.
The +animateWithDuration:animations:completion:
call returns immediately, so as soon as the second animation runs, self.componentDetailController
is nil
and all the subsequent view-transformation calls go nowhere. Store self.componentDetailController.view
into its own variable and reference that in your animation blocks. Eg:
UIView *detailView = self.componentDetailController.view;
detailView.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.1 animations:^{
detailView.alpha = 1;
// …
}];
self.componentDetailController = nil;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.