Hi Readers,
In our app we usually make custom alerts which we need to animate at the time adding it on its superview.
To achieve it with you custom view make a category like this :
Put this code into your .h file of category named as UIView+AnimateView :
@interface UIView (AnimateView)
- (void)addSubviewWithBounce:(UIView*)subview;
- (void)removeSubviewWithAnimation:(UIView*)subview;
@end
After that use following code in your .m file:
@implementation UIView (AnimateView)
- (void)addSubviewWithBounce:(UIView*)subview
{
subview.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[self addSubview:subview];
[UIView animateWithDuration:0.3/1.5 animations:^{
CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
subview.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
subview.transform = CGAffineTransformIdentity;
}];
}];
}];
}
- (void)removeSubviewWithAnimation:(UIView*)subview{
subview.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.3/1.5 animations:^{
subview.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
} completion:^(BOOL finished) {
[subview removeFromSuperview];
}];
}
@end
Just import this category on any controller and call these function like :
[self.view removeSubviewWithAnimation:subview];
[self.view addSubviewWithBounce:subview];
Thanks. Happy coding
0 Comment(s)