写一个气泡动画视图

首先需要找一张气泡的矢量图

写一个气泡动画视图_第1张图片

效果图:

写一个气泡动画视图_第2张图片写一个气泡动画视图_第3张图片

 

创建自定义FLGGrowCourceTipView  继承UIView

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];

    if (self) {

        [self createView];

    }

    return self;

}

- (void)createView{

    self.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.30];

   ///  添加一个手势,,点击PopView试图  时 动画隐藏PopView

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];

    [self addGestureRecognizer:tap];

    ///  创建气泡imageview  对imageview取一小部分进行拉伸(聊天气泡实现)

    self.backImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"用户汽泡"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10) resizingMode:UIImageResizingModeStretch]];

    [self addSubview:self.backImageView];

/// 初始气泡为一点

    self.backImageView.frame = CGRectMake(self.frame.size.width-kCustomWidth_(30), kCustomHeight_(70), 0, 0);

    [UIView animateWithDuration:0.2 animations:^{

/// 开始动画  气泡变大

        self.backImageView.frame = CGRectMake(self.frame.size.width/2+kCustomWidth_(30), kCustomHeight_(70), self.frame.size.width/2-kCustomWidth_(60), kCustomHeight_(180));

        

    }completion:^(BOOL finished) {

//// 动画结束   气泡试图上添加相应的控件

        self.tipLabel = [[UILabel alloc] init];

        [self.backImageView addSubview:self.tipLabel];

        self.tipLabel.numberOfLines = 0;

        self.tipLabel.text = NSLocalizedString(@"The short-term scoring rate of a certain subject is equal to or equal to the average scoring rate, and the amount of rehearsal is equal to or equal to the average rehearsing amount. The subject name is green, if both are less than, it is red, otherwise it will not be colored.", nil);

        self.tipLabel.font = FontWithSize(15);

        self.tipLabel.sd_layout.leftSpaceToView(self.backImageView, kCustomWidth_(5)).topSpaceToView(self.backImageView, kCustomWidth_(5)).rightSpaceToView(self.backImageView, kCustomWidth_(5)).bottomSpaceToView(self.backImageView, kCustomWidth_(5));

    }];

    

}

- (void)tapAction{

    //先将未到时间执行前的任务取消,,,,防止点击过快动画出错(防止变态点击)

    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(allTaskBeginDownload)object:nil];

    [self performSelector:@selector(allTaskBeginDownload)withObject:nil afterDelay:0.2f];

}

-(void) allTaskBeginDownload{

//// 点击了试图 气泡动画缩成一点,,,动画结束后 将所有试图移除

    [UIView animateWithDuration:0.2 animations:^{

        self.tipLabel.hidden = YES;

        self.backImageView.frame = CGRectMake(self.frame.size.width-kCustomWidth_(30), kCustomHeight_(70), 0, 0);

    }completion:^(BOOL finished) {

        [self.tipLabel removeFromSuperview];

        [self.backImageView removeFromSuperview];

        [self removeFromSuperview];

        self.tipLabel = nil;

        self.backImageView = nil;

    }];

}

 

 

需要气泡提示的controller

 

- (void)tipViewAction{

    FLGGrowCourceTipView *view = [[FLGGrowCourceTipView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

    [[UIApplication sharedApplication].keyWindow addSubview:view];

    

}

你可能感兴趣的:(写一个气泡动画视图)