UIView的动画,如何使其光滑? [英] UIView animation, how make it smooth?

查看:153
本文介绍了UIView的动画,如何使其光滑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现简单的动画来改变我用这个code查看的位置是:

I try to implement simple animation to change view position I use this code:

[UIView animateWithDuration:0.4 animations: ^{
self.greenIm.frame = CGRectMake(self.roundView.frame.origin.x, self.roundView.frame.origin.y -   110, 60, 60);
 self.greenIm.layer.cornerRadius = self.greenIm.frame.size.height / 2;
}

但我所看到的,我的观点圆润去self.greenIm新位置,而不会舍入,只在最后留圆润,看起来不错。

But what I see, my rounded view self.greenIm go to new position without rounding and only at the end stay rounded, looks bad.

后来我想改变的另一个视图大小,但我需要的相同信息中心:

Later I want change size of another View but I need same center:

[UIView animateWithDuration:0.4 animations: ^{
self.cup.frame = CGRectMake(self.cup.frame.origin.x, self.cupImage.frame.origin.y, self.cup.frame.size.width - 20, self.cup.frame.size.height - 20);
self.cup.center = self.centerPoint;
}

在这里,我看到一样的,第一个视图改变大小后定心。

Here I see same, first view change size later centering.

如何解决?如何我理解的UIView动画动漫的所有属性不能一次。请帮助。

How fix it ? How I understand UIView animation anime all properties not in one time. Please help.

推荐答案

有关你的第一个问题,苹果的文档说,你可以动画的属性,这是动画。

For you first problem, Apple documentation says that you can animate the properties, which are animatable.

包含修改提交的意见块对象。这是你编程方式更改您的视图层次的意见,任何的动画属性即可。此块不带参数,没有返回值。此参数不能为NULL。

A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.

如果您看到的的UIView 的属性,你会发现,层的文档不是动画。您需要使用核心动画来实现这一目标。使用低于code。我使用的的UILabel 此示例code。看看这有助于。

If you see the documentation for UIView properties, you will find that layer is not animatable. You need to use Core Animation to achieve this. Use the below code. I am using a UILabel for this sample code. See if this helps.

  CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
  [anim setFromValue:[NSValue valueWithNonretainedObject:[NSNumber numberWithDouble:10.0]]];
  lblView.layer.cornerRadius = 30.0; 
  [anim setDuration:6];
  [lblView.layer addAnimation:anim forKey:@"move"];

在这个非常相同的方式,你可以创建的位置的财产另一个动画对象,并根据需要更改框。该动画添加到的的和动画都将并行启动。

In this very same fashion you can create another animation object for position property and change the frame as desired. Add that animation to layer and both animation will start in parallel.

这篇关于UIView的动画,如何使其光滑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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