Reputation:
I added an UIView
with some animation by using the following code:
CGRect a = CGRectMake(10,10,295,460);
UIView *customView = [[UIView alloc]initWithFrame:a];
customView.tag=10;
[self.tableView addSubview:customView];
[UIView animateWithDuration:1.0
animations:
^{
customView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}
];
When I try to remove the UIView
with animation, the animation seems not working. The view is just getting removed without any animation.
Here is what I have to remove the UIView
with animation:
UIView *removeView=[self.tableView viewWithTag:10] ;
removeView .transform = CGAffineTransformMakeScale(1.0f, 1.0f);
[removeView removeFromSuperview];
[UIView animateWithDuration:1.5
animations:
^{
removeView .transform = CGAffineTransformMakeScale(0.0f, 0.0f);
}
];
I tried by placing the [UIView animateWithDuration:1.5 ...
block before and after the [removeView removeFromSuperview]
, but none gave me the animation. Kindly help me out in this.
Upvotes: 4
Views: 5287
Reputation: 4425
Refer the following sample from Apple.
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
completion:NULL];
The above code creates a flip transition for the specified container view. At the appropriate point in the transition, one subview is removed and another is added to the container view. This makes it look as if a new view was flipped into place with the new subview, but really it is just the same view animated back into place with a new configuration.
May be the animation type you need to manage.
Refer:- https://developer.apple.com/documentation/uikit/uiview/1622574-transition
Upvotes: 0
Reputation: 8105
Try this one, it's worked for me:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
removeView.transform = CGAffineTransformMakeTranslation(removeView.frame.origin.x,1000.0f + (removeView.frame.size.height/2));
aview.alpha = 0;
[UIView commitAnimations];
Upvotes: 0
Reputation: 531
Some changes:
UIView *removeView=[self.tableView viewWithTag:10] ;
removeView .transform = CGAffineTransformMakeScale(1.0f, 1.0f);
[removeView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5];
[UIView animateWithDuration:1.5
animations:
^{
removeView .transform = CGAffineTransformMakeScale(0.01f, 0.01f);
}
];
Try setting your final transform to something small but nonzero.
Upvotes: 1
Reputation: 44
Try waiting to remove the view until the animation is over:
[removeView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.0];
Upvotes: 0
Reputation: 1136
[UIView animateWithDuration:1.5 animations:^ {
removeView.transform = CGAffineTransformMakeScale(0.0f, 0.0f);
} completion:^(BOOL finished) {
[removeView removeFromSuperview];
}];
Upvotes: 4