UIImageViewanimation无法正常工作

我想通过animation使UIImageView的宽度更大。 我有一个UIView和在故事板上制作的UIImageView。 我想要达到的目的是看起来像是从左到右的缩放,并保持原来的位置。 我已经尝试了下面的代码,但它所做的是从其父视图的左上angularanimation图像视图,并移动和缩放它,直到它到达位置并从头开始缩放。

[UIView animateWithDuration:4.0f delay:1.0f options:UIViewAnimationCurveEaseOut animations:^{ CGRect currentFrame = self.imageview1.frame; currentFrame.size.width = 150; self.imageview1.frame = currentFrame; }completion:nil]; 

任何想法为什么这种行为?

有点迟来的答案,但我解决了这个问题。 看起来,如果启用了自动布局function,则无法更改代码中的视图框架。 相反,你需要animation的视图的约束,你可以在故事板中设置,然后像这样的animation:

 [self.view layoutIfNeeded]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.bottomViewY.constant = -196; [self.view layoutIfNeeded]; } completion:nil]; 

self.bottomViewY是一个被指定为IBOulet的约束。 您需要调用layoutIfNeeded,因为它将更新约束。