记录一下POP使用时遇到的问题

FaceBook的POP的动画框架确实挺好看的,使用起来也很简单。在使用的时候有几个点,也要注意一下。

- (void)clickBottomButtonAction:(UIButton *)sender{

//    self.userInteractionEnabled = NO;
    for (UIButton *button in self.bottomButtonArray) {
        CGRect frame = button.frame;
        frame.origin.y = _originY;
        button.frame = frame;
        button.selected = NO;
    }
    sender.selected = YES;
    POPSpringAnimation *anSpring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    anSpring.fromValue = @(_originY);
    anSpring.toValue = @(_originY+10);
    anSpring.delegate = self;
    anSpring.springBounciness = 20.0f;
    [sender pop_addAnimation:anSpring forKey:[NSString stringWithFormat:@"BottomButtonPositionY%ldld",(long)sender.tag]];
//    anSpring.completionBlock = ^(POPAnimation *anim, BOOL finished) {
//        if (finished) {
//            self.userInteractionEnabled = YES;
//        }
//    };
    
}

碰到了一个这样的bug,当一个POP动画还没有结束,发起另外一个POP动画同时使用frame值去恢复button的初始状态,会发现这时候设置frame值无效。 (猜想可能跟pop实现机制有关系)

修改前.gif

解决方法:
1.使用上面代码注释中的self.userInteractionEnabled = YES;方法解决,这种解决方案会让用户体验非常差!
2.同样使用POP动画还原按钮状态,demo如下:

    if (_selectButton) {
        self.selectButton.selected = NO;
        POPBasicAnimation *anSpring = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPositionY];
        CGFloat h = self.selectButton.frame.size.height/6;
        anSpring.toValue =  @(SCREEN_HEIGHT-h);
        [self.selectButton pop_addAnimation:anSpring forKey:[NSString stringWithFormat:@"BottomButtonPositionY%ld",(long)self.selectButton.tag]];
    }
    
    self.selectButton = sender;
    sender.selected = YES;
    POPSpringAnimation *anSpring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    anSpring.fromValue = @(_originY);
    anSpring.toValue = @(_originY+10);
    anSpring.springBounciness = 20.0f;
    [sender pop_addAnimation:anSpring forKey:[NSString stringWithFormat:@"BottomButtonPositionY%ld",(long)sender.tag]];
修改后.gif

你可能感兴趣的:(记录一下POP使用时遇到的问题)