FaceBook的POP的動(dòng)畫框架確實(shí)挺好看的债蓝,使用起來(lái)也很簡(jiǎn)單耗美。在使用的時(shí)候有幾個(gè)點(diǎn),也要注意一下盟劫。
- (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;
// }
// };
}
碰到了一個(gè)這樣的bug夜牡,當(dāng)一個(gè)POP
動(dòng)畫還沒(méi)有結(jié)束,發(fā)起另外一個(gè)POP
動(dòng)畫同時(shí)使用frame
值去恢復(fù)button
的初始狀態(tài)侣签,會(huì)發(fā)現(xiàn)這時(shí)候設(shè)置frame值無(wú)效塘装。 (猜想可能跟pop實(shí)現(xiàn)機(jī)制有關(guān)系)
修改前.gif
解決方法:
1.使用上面代碼注釋中的self.userInteractionEnabled = YES;
方法解決急迂,這種解決方案會(huì)讓用戶體驗(yàn)非常差!
2.同樣使用POP動(dòng)畫還原按鈕狀態(tài),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