简体   繁体   English

UIView动画不会移动视图

[英]UIView animation doesn't move the view

This is the code I use for the animation. 这是我用于动画的代码。

        NSLog(@"SlideLoadingViewOut : frame: X:%f, Y:%f", self.loadingView.frame.origin.x, self.loadingView.frame.origin.y);
        [UIView animateWithDuration:time animations:^{
            self.loadingView.frame = CGRectMake(320, 0, self.loadingView.frame.size.width, self.loadingView.frame.size.height);
            NSLog(@"SlideLoadingViewOut : frame: X:%f, Y:%f", self.loadingView.frame.origin.x, self.loadingView.frame.origin.y);
        } completion:^(BOOL finished) {
            NSLog(@"SlideLoadingViewOut : frame: X:%f, Y:%f", self.loadingView.frame.origin.x, self.loadingView.frame.origin.y);
        }];

This is the output in the console I get: 这是我得到的控制台中的输出:

Before the animation starts: 在动画开始之前:

SlideLoadingViewOut : frame: X:0.000000, Y:0.000000

In the animation block: 在动画块中:

SlideLoadingViewOut : frame: X:320.000000, Y:0.000000

In the completion block: 在完成块中:

SlideLoadingViewOut : frame: X:0.000000, Y:0.000000

The view doesn't move. 视图不会移动。 Anyone knows why this might happen. 任何人都知道为什么会发生这种情况。

Wild speculation 疯狂的猜测

for some reason the animation block doesn't like CGRectMake being within the block, try creating it earlier. 由于某些原因,动画块不喜欢CGRectMake位于该块中,请尝试更早创建它。

Well, someone answered this earlier but for some reason his comment disappeared. 好吧,有人较早地回答了这个问题,但是由于某种原因,他的评论消失了。 Apperntley I was changing the frame on a different thread than the main, I executed it on the main thread using, and it worked. Apperntley我在与主线程不同的线程上更改了框架,我在主线程上使用对其执行了,并且有效。

dispatch_async(dispatch_get_main_queue(), ^{
   // do work here
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM