From b1b31b495ffb18e261b96840f999f6278b5beb7b Mon Sep 17 00:00:00 2001 From: isaced Date: Tue, 16 Jun 2015 17:02:36 +0800 Subject: [PATCH] Add a simple pop animation --- Example/ISEmojiViewSample/ViewController.m | 1 + ISEmojiView/ISEmojiView.h | 12 +++++++ ISEmojiView/ISEmojiView.m | 37 +++++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Example/ISEmojiViewSample/ViewController.m b/Example/ISEmojiViewSample/ViewController.m index 76bb119..631d1b9 100644 --- a/Example/ISEmojiViewSample/ViewController.m +++ b/Example/ISEmojiViewSample/ViewController.m @@ -27,6 +27,7 @@ // init ISEmojiView ISEmojiView *emojiView = [[ISEmojiView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 216)]; emojiView.delegate = self; + emojiView.inputView = self.textView; self.textView.inputView = emojiView; [self.textView becomeFirstResponder]; diff --git a/ISEmojiView/ISEmojiView.h b/ISEmojiView/ISEmojiView.h index 0efae4e..f7c67cd 100644 --- a/ISEmojiView/ISEmojiView.h +++ b/ISEmojiView/ISEmojiView.h @@ -30,6 +30,18 @@ */ @property (nonatomic, strong) UIPageControl *pageControl; +/** + * the input view + */ +@property (nonatomic, strong) UIView *inputView; + +/** + * Are animation allowed (default:YES) + * + * require set inputView (eg:TextField,TextView) + */ +@property (nonatomic, assign) BOOL popAnimationEnable; + @end /** diff --git a/ISEmojiView/ISEmojiView.m b/ISEmojiView/ISEmojiView.m index 450a9f9..004f115 100644 --- a/ISEmojiView/ISEmojiView.m +++ b/ISEmojiView/ISEmojiView.m @@ -110,7 +110,8 @@ static const CGFloat EmojiFontSize = 32; [self.pageControl addTarget:self action:@selector(pageControlTouched:) forControlEvents:UIControlEventValueChanged]; [self addSubview:self.pageControl]; - + // default allow animation + self.popAnimationEnable = YES; } return self; } @@ -138,10 +139,36 @@ static const CGFloat EmojiFontSize = 32; animation.duration = 0.1; animation.autoreverses = YES; [button.layer addAnimation:animation forKey:nil]; - - // Callback - if ([self.delegate respondsToSelector:@selector(emojiView:didSelectEmoji:)]) { - [self.delegate emojiView:self didSelectEmoji:button.titleLabel.text]; + + if (self.popAnimationEnable) { + // Animation emojibutton + UIButton *animationEmojiButton = [UIButton buttonWithType:UIButtonTypeCustom];; + [animationEmojiButton setTitle: [button titleForState:UIControlStateNormal] forState:UIControlStateNormal]; + animationEmojiButton.titleLabel.font = [UIFont fontWithName:@"Apple color emoji" size:EmojiFontSize];\ + + // Conver frame from scrollview to self and add to self + animationEmojiButton.frame = [button.superview convertRect:button.frame toView:self]; + [self addSubview:animationEmojiButton]; + + // get animation traget position from input view + CGPoint newPoint = [self.inputView convertPoint:self.inputView.center toView:self]; + [UIView animateWithDuration:0.3 animations:^{ + animationEmojiButton.center = newPoint; + animationEmojiButton.alpha = 0; + } completion:^(BOOL finished) { + if (finished) { + // Callback + if ([self.delegate respondsToSelector:@selector(emojiView:didSelectEmoji:)]) { + [self.delegate emojiView:self didSelectEmoji:button.titleLabel.text]; + } + [animationEmojiButton removeFromSuperview]; + } + }]; + }else{ + // Callback + if ([self.delegate respondsToSelector:@selector(emojiView:didSelectEmoji:)]) { + [self.delegate emojiView:self didSelectEmoji:button.titleLabel.text]; + } } }