POP学习总结

例子一:UITableViewCell Animation

UITableViewCell Demo下载:Demo
效果图:

POP学习总结_第1张图片
演示Demo.gif

我们创建一个动画在tableViewCell上,首先添加一个放大的动画当我们点击cell的时候,当我们手离开屏幕的时候,我们用将cell上缩回原先的大小用spring animation;
重写cell中的setHighlighted方法,代码如下:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    if (self.highlighted) {
        POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewScaleXY];
        //duration 持续时间
        scaleAnimation.duration = 0.1;
        //点击时,字体大小
        scaleAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1, 1)];
        [self.titleLabel pop_addAnimation:scaleAnimation forKey:@"scalingUp"];
    } else {
        POPSpringAnimation *sprintAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];
        //缩小的时候,字体大小
        sprintAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(0.9, 0.9)];
        //缩小后弹回字体本来大小
        sprintAnimation.velocity = [NSValue valueWithCGPoint:CGPointMake(1, 1)];
        //弹力值
        sprintAnimation.springBounciness = 20.f;
        [self.titleLabel pop_addAnimation:sprintAnimation forKey:@"springAnimation"];
    }
}

Animating UIButton动画

UIButton Demo下载:Demo
效果图:

POP学习总结_第2张图片
演示Demo.gif

实现UITextField的代理方法,在这个方法中我们可以监控用户输入和删除文字,内部的实现如下:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    NSString *comment;
    
    if(range.length == 0){
        comment = [NSString stringWithFormat:@"%@%@", textField.text, string];
    }else{
        comment = [textField.text substringToIndex:textField.text.length - range.length];
    }
    
    if (comment.length == 0) {
        [self setupZanBtn];
    }else{
        [self setupSendBtn];
    }
    
    return YES;
}

之后我们实现setupZanBtn和setuasendbtn

//发送按钮
-(void)setupSendBtn{
    if (self.sendBtn.isHidden) {
        self.zanBtn.hidden = YES;
        self.sendBtn.hidden = NO;
        POPSpringAnimation *sprintAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];
        sprintAnimation.velocity = [NSValue valueWithCGPoint:CGPointMake(8, 8)];
        sprintAnimation.springBounciness = 20.f;
        [self.sendBtn pop_addAnimation:sprintAnimation forKey:@"sendAnimation"];
    }
}

//赞按钮
-(void)setupZanBtn{
    self.zanBtn.hidden = NO;
    self.sendBtn.hidden = YES;
    POPSpringAnimation *spin = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];
    spin.fromValue = @(M_PI / 4);
    spin.toValue = @(0);
    spin.springBounciness = 20;
    spin.velocity = @(10);
    [self.zanBtn.layer pop_addAnimation:spin forKey:@"likeAnimation"];
}

未完待续。。。

勤学如早春之苗,不见其增,日有所涨。
辍学如磨刀之石,不见其减,日有所损。

你可能感兴趣的:(POP学习总结)