记录一下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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AGI阅读 16,018评论 3 119
  • 文/孤鸟差鱼 一场富人的游戏 唯独对爱 开的条件 优渥
    孤鸟差鱼阅读 208评论 0 3
  • 别理解我 我自己都不理解我 别注意我 我从没时间注意我 别赞美我 我都没资格赞美我 别嘲笑我 我很喜欢现在的我 我...
    蠢谦阅读 275评论 0 1
  • 最近在部署项目启动tomcat的时候,发现启动超慢,启动一次要4-5分钟。在查看tomcat的日志的时候看到:WA...
    半亩荒地阅读 464评论 0 0
  • 已经忘了几号到的训练营,只知道每时每刻都有新的收获,有理论的,有实践的,在这里的学习是为了日后回到工作岗...
    居然电器城韩瑞萍1863568阅读 270评论 0 0