2014-10-28 178 views
0

我有一個名爲change shape功能:奇怪的UILabel和UIButton的行爲

- (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。出於某種原因,UIButton上的圖像只會在UILabel更改後纔會更改。有人知道這可能是爲什麼嗎?

+0

@dasblinkenlight我在說,setImage似乎在外部完成塊內的完成塊之後執行。知道我在說什麼? – Apollo 2014-10-28 20:11:46

回答

-1

在應用位置更改和新圖像後,致電[self.shapeButton layoutIfNeeded]

+0

這類作品。現在第二個uiview動畫似乎不會被稱爲 – Apollo 2014-10-28 20:15:13

+0

Again ...在調整動畫塊內部的座標之後添加'layoutIfNeeded'。 – sha 2014-10-28 20:16:05

+0

這不起作用。請你詳細說明我應該在哪裏插入這些行? – Apollo 2014-10-28 20:20:08