[英]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.