动画的UIImageView不能正常工作 [英] UIImageView animation not working correctly

查看:132
本文介绍了动画的UIImageView不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过动画较大一个的UIImageView的宽度。我有带的UIView,并在UIImageView的故事板制作。我想实现的是,这样它看起来像视图从左至右缩放,并保持原来的位置。我曾尝试以下code,但它所做的是从它的父视图的左上角的动画和ImageView的移动,直到它到达的位置和规模从起初进行缩放。

I want to make the width of an UIImageView larger through an animation. I have an UIView with and UIImageView made in the story board. What I want to achieve is so that it looks like the view is scaling from left to right, and keeping its original position. I have tried the following code, but what it does is animating the imageview from the top left corner of its parent view and moving and scaling it until it reaches the position and scale it had from the beginning.

[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];

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

Any ideas why this behaviour?

推荐答案

一个有点晚了答案,但我解决了这个问题。如此看来,如果启用了自动布局不能更改的意见,code中的框架。相反,你需要动画视图,您可以在故事板设置,然后动画这样的约束:

A bit late answer, but I solved the problem. It seems that you cannot change the frame of views in code if autolayout is enabled. Instead you need to animate the constraints of the view, which you can set up in the storyboard and then animate like this:

[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因为它会更新的约束。

self.bottomViewY is a constraint which is assigned as an IBOulet. You need to call layoutIfNeeded as it will update the constraints.

这篇关于动画的UIImageView不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆