[英]Strange UILabel and UIButton behavior
我有一个名为change shape
的功能:
- (void)changeShape {
NSLog(@"**** CHANGE SHAPE ****");
/* Set previous shape to current shape */
self.previousShape = self.currentShape;
/* Transition old shape out of view */
[UIView animateWithDuration:.4 animations:^(void){
[self.shapeButton setCenter:CGPointMake(self.view.frame.size.width+200, self.view.frame.size.height/2)];
} completion:^(BOOL finished){
if (finished) {
/* Set new current shape */
self.currentShape = [NSString stringWithFormat:@"%@",self.shapes[(arc4random() % [self.shapes count])]];
[self.shapeButton setImage:[UIImage imageNamed:self.currentShape] forState:UIControlStateNormal];
/* Transition new shape into view */
[self.shapeButton setCenter:CGPointMake(-200, self.view.frame.size.height/2)];
[UIView animateWithDuration:.3 animations:^(void){
[self.shapeButton setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
} completion:^(BOOL completed){
if (completed) {
[self changeScore];
}
}];
}
}];
}
- (void)changeScore {
self.score++;
[self.scoreLabel setText:[NSString stringWithFormat:@"%i",self.score]];
}
此功能将UIButton移出屏幕,然后将其动画化回屏幕。 在最终动画的结尾,我想增加分数并在屏幕上更改UILabel
。 由于某些原因,只有在更改了UILabel之后,UIButton上的图像才会更改。 有人知道为什么会这样吗?
应用位置更改和新图像后,调用[self.shapeButton layoutIfNeeded]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.