2014-10-28 147 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