首页 > 代码库 > 新浪微博客户端(46)-点击表情按钮弹出表情

新浪微博客户端(46)-点击表情按钮弹出表情

 

DJEmotionPageView.m

/**
 * 点击表情监听方法
 * param btn 点击的表情按钮
 */
- (void)emotionBtnClick:(DJEmotionButton *)btn {

    // 获取当前应用程序最顶层的窗口
    UIWindow *lastWindow = [[UIApplication sharedApplication].windows lastObject];
    
    // 转换btn当前坐标系
    CGRect newFrame = [btn convertRect:btn.bounds toView:nil];
    
    self.popView.centerX = CGRectGetMidX(newFrame);
    self.popView.y = CGRectGetMaxY(newFrame) - self.popView.height;
    
    // 将当前点击按钮的表情模型传递给popview
    self.popView.emotion = btn.emotion;
    
    [lastWindow addSubview:self.popView];

}

DJEmotionPopView.m

#import "DJEmotionPopView.h"
#import "DJEmotionButton.h"


@interface DJEmotionPopView()

// 表情
@property (weak, nonatomic) IBOutlet DJEmotionButton *emotionView;

@end


@implementation DJEmotionPopView

+ (instancetype)popView {

    return [[[NSBundle mainBundle] loadNibNamed:@"DJEmotionPopView" owner:nil options:nil] lastObject];
}


- (void)setEmotion:(DJEmotion *)emotion {
    _emotion = emotion;
    self.emotionView.emotion = emotion;
}


#pragma mark - 当从Xib中加载View的时候不会调用initWithFrame方法,则是直接调用initWithCoder及awakeFromNib方法


- (instancetype)initWithCoder:(NSCoder *)decoder
{
    self = [super initWithCoder:decoder];
    if (self) {
     
        self.emotionView.titleLabel.font = [UIFont systemFontOfSize:32];
        
    }
    return self;
}


- (void)awakeFromNib {


}



@end

最终效果:

技术分享

 

新浪微博客户端(46)-点击表情按钮弹出表情