Animation Blocks resets to original position after updating text

后端 未结 2 1759
清歌不尽
清歌不尽 2020-12-10 12:05

I\'m currently testing my apps for the release of IOS 8. I noticed that after I performed an animation block, the animation resets if I update the text of any label. I ran a

相关标签:
2条回答
  • 2020-12-10 12:34

    This problem can be caused by having Auto Layout set on the UIView. Strictly speaking, if you're using Auto Layout, then you shouldn't animate the absolute position of objects -- you should animate their constraints instead.

    Changing the label text once your animation is underway triggers a layout refresh, and iOS shuffles everything around to comply with the original view constraints. (I suspect this is a behavioural change from iOS7).

    Quick fix: un-check Auto Layout on the View, and this should work as expected.

    0 讨论(0)
  • 2020-12-10 12:37

    Try this. Put the desired animation in the finish block also.

        - (IBAction)move:(id)sender {
    
        [UIView animateWithDuration:0.4 delay:0.0
                         options:UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
    
    
    self.myButton.center = CGPointMake(200, 300);
                     }completion:^(BOOL finished){
    
    
    
             if(finished){
                             self.myLabel.text=@"moved";
     self.myButton.center = CGPointMake(200, 300);
                         }
    
                     }];
    }
    
    0 讨论(0)
提交回复
热议问题