123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- //
- // FLRiseViewHelper.m
- // FirstLink
- //
- // Created by unicode on 14-11-18.
- // Copyright (c) 2014年 FirstLink. All rights reserved.
- //
- #import "FloatDownView.h"
- #import "FirstLinkAppDelegate.h"
- #import "FLControllerHelper.h"
- @interface FloatDownView ()
- @property (nonatomic, assign) BOOL isShowing;
- @property (nonatomic, strong) UILabel *textLabel;
- @property (nonatomic, strong) UIImageView *leftIconImageView;
- @property (nonatomic, strong) UIButton *rightCancelBtn;
- @property (nonatomic, strong) UITapGestureRecognizer *clickMoreGestureRecognizer;
- @property (nonatomic, strong) UITapGestureRecognizer *clickCloseGestureRecognizer;
- @property (nonatomic, weak) UIView *pView;
- @property (nonatomic, assign) CGRect raiseViewFrame;
- @property (nonatomic, copy) void (^callBack)(id object);
- @end
- @implementation FloatDownCommand
- @end
- @implementation FloatDownView
- + (FloatDownView *)sharedInstance {
- static FloatDownView *sharedRiseViewHelperInstance = nil;
-
- static dispatch_once_t once_token;
- dispatch_once(&once_token, ^{
- sharedRiseViewHelperInstance = [[self alloc] init];
- });
-
- return sharedRiseViewHelperInstance;
- }
- - (void)prepareFloatDownViewFrame:(CGRect)frame inView:(UIView *)pView clickCallBack:(void (^)(id))callBack {
- self.raiseViewFrame = frame;
- self.pView = pView;
- self.callBack = callBack;
- }
- - (void)sendCommand:(FloatDownCommand *)command {
-
- if (self.messageQueue.count) return; // 一次只显示一个
-
- if (command) {
- [self.messageQueue addObject:command];
- }
-
- FloatDownCommand *latestCommand = self.messageQueue.lastObject;
- if (latestCommand) {
- switch (latestCommand.type) {
- case RiseViewTypeDefault: {
- break;
- }
- case RiseViewTypeAutoClose: {
- [self layoutForAutoCloseView];
- [NSTimer scheduledTimerWithTimeInterval:3.0
- target:self
- selector:@selector(closeView:)
- userInfo:nil
- repeats:FALSE];
- break;
- }
- case RiseViewTypeClickClose: {
- [self layoutForAutoClickCloseView];
- // [self.textLabel addGestureRecognizer:self.clickCloseGestureRecognizer];
- break;
- }
- case RiseViewTypeClickMore: {
- [self.textLabel addGestureRecognizer:self.clickMoreGestureRecognizer];
- break;
- }
- default:
- break;
- }
-
-
- [self riseBannerInView:self.pView
- content:latestCommand.content
- bgcolor:[self bgcolorWithType:latestCommand.type]
- textColor:[self textColorWithType:latestCommand.type]
- type:latestCommand.type];
- }
- }
- - (UIColor*)bgcolorWithType:(RiseViewType)type{
- switch (type) {
- case RiseViewTypeDefault:
- case RiseViewTypeAutoClose:
- case RiseViewTypeClickClose: {
- return [UIColor colorWithRed:1.0
- green:99.0/255.0
- blue:99.0/255.0 alpha:0.9];
- break;
- }
- case RiseViewTypeClickMore: {
- return [UIColor yellowColor];
- break;
- }
- default:
- break;
- }
- return [UIColor blackColor];
- }
- - (UIColor*)textColorWithType:(RiseViewType)type{
- switch (type) {
- case RiseViewTypeDefault:
- case RiseViewTypeAutoClose:
- case RiseViewTypeClickClose:
- case RiseViewTypeClickMore: {
- return [UIColor whiteColor];
- break;
- }
- default:
- break;
- }
- return [UIColor whiteColor];
- }
- - (void)riseBannerInView:(UIView *)pView
- content:(NSString *)content
- bgcolor:(UIColor *)bgcolor
- textColor:(UIColor *)textColor
- type:(RiseViewType)type
- {
- self.textLabel.textColor = textColor;
- self.textLabel.text = content;
- self.backgroundColor = bgcolor;
-
- self.frame = CGRectOffset(self.raiseViewFrame, 0, - DOWN_COMMAND_HEIGHT);
- [pView addSubview:self];
-
- __weak FloatDownView *weakSelf = self;
- [UIView animateWithDuration:0.4
- animations:^{
- weakSelf.frame = weakSelf.raiseViewFrame;
- } completion:^(BOOL finished) {
- if (type == RiseViewTypeClickClose) {
- // [weakSelf addSubview:weakSelf.closeImageView];
- }
- }];
- }
- #pragma mark -
- - (void)layoutForAutoCloseView {
-
- [self clearContent];
- self.backgroundColor = [UIColor colorWithRed:73.0/255.0
- green:208/255.0
- blue:187.0/255.0 alpha:0.9];
-
- WeakSelf(weakSelf);
- [self addSubview:self.textLabel];
- [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(weakSelf).with.offset(0);
- make.centerX.equalTo(weakSelf).with.offset(12);
- make.width.mas_greaterThanOrEqualTo(10);
- }];
-
- [self addSubview:self.leftIconImageView];
- [self.leftIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(weakSelf.textLabel.mas_left).with.offset(-12);
- make.centerY.equalTo(weakSelf);
- make.size.mas_equalTo(CGSizeMake(15, 15));
- }];
- }
- - (void)layoutForAutoClickCloseView{
-
- [self clearContent];
- self.backgroundColor = [UIColorFromRGB(0xff6362) colorWithAlphaComponent:0.9];
-
- [self addSubview:self.textLabel];
- [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
-
- [self addSubview:self.rightCancelBtn];
- [self.rightCancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self);
- make.width.mas_equalTo(45);
- make.height.centerY.equalTo(self);
- }];
- }
- - (void)clearContent{
- for (UIView *subView in self.subviews) {
- [subView removeFromSuperview];
- }
- }
- #pragma mark - Generate
- - (NSMutableArray*)messageQueue {
- if (!_messageQueue) {
- _messageQueue = [NSMutableArray array];
- }
- return _messageQueue;
- }
- - (UILabel*)textLabel {
- if (!_textLabel) {
- _textLabel = [[UILabel alloc] init];
- _textLabel.textAlignment = NSTextAlignmentCenter;
- _textLabel.font = [UIFont systemFontOfSize:13.0];
- }
- return _textLabel;
- }
- - (UIImageView*)leftIconImageView {
- if (!_leftIconImageView) {
- _leftIconImageView = [[UIImageView alloc] init];
- _leftIconImageView.image = [UIImage imageNamed:@"NewContentImageIcon"];
- }
- return _leftIconImageView;
- }
- - (UIButton *)rightCancelBtn{
- if (_rightCancelBtn == nil) {
- _rightCancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_rightCancelBtn setImage:[UIImage imageNamed:@"red_cancel"] forState:UIControlStateNormal];
- [_rightCancelBtn addTarget:self
- action:@selector(clickCancelBtn:)
- forControlEvents:UIControlEventTouchUpInside];
- }
- return _rightCancelBtn;
- }
- - (UITapGestureRecognizer*)clickMoreGestureRecognizer {
- if (!_clickMoreGestureRecognizer) {
- _clickMoreGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(clickMoreAction:)];
- _clickMoreGestureRecognizer.numberOfTapsRequired = 1;
- }
-
- return _clickMoreGestureRecognizer;
- }
- - (UITapGestureRecognizer*)clickCloseGestureRecognizer {
- if (!_clickCloseGestureRecognizer) {
- _clickCloseGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(clickCloseAction:)];
- _clickCloseGestureRecognizer.numberOfTapsRequired = 1;
- }
-
- return _clickCloseGestureRecognizer;
- }
- #pragma mark - Action Method
- - (IBAction)closeView:(id)sender {
- __weak FloatDownView *weakSelf = self;
- [UIView animateWithDuration:0.4
- animations:^{
- weakSelf.frame = CGRectMake(0, -CGRectGetHeight(weakSelf.raiseViewFrame), [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(weakSelf.raiseViewFrame));
- } completion:^(BOOL finished) {
- [weakSelf removeFromSuperview];
- [weakSelf.messageQueue removeAllObjects];
- }];
- }
- - (IBAction)clickMoreAction:(id)sender {
- [self closeView:nil];
-
- if (self.callBack) {
- self.callBack(nil);
- }
- }
- - (void)clickCancelBtn:(UIButton *)sender{
- [self closeView:nil];
- }
- - (IBAction)clickCloseAction:(id)sender {
- [self closeView:nil];
- }
- @end
|