UIView使用子视图开始动画 [英] UIView beginAnimations with subviews

查看:123
本文介绍了UIView使用子视图开始动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个视图提供了一个简单易用的缩放动画,它以点开始并动画到最大屏幕尺寸:

I have a nice and easy "zoom" animation for a view, which starts as a dot and animates up to full screen size:


        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        myView.frame = CGRectMake(0,0,320,480);
        myView.transform = CGAffineTransformIdentity;  
        [UIView commitAnimations];

到目前为止一直很好:-)

So far so good :-)

问题在于,当我添加子视图到myView,令我惊讶的是,他们不遵循他们的superview的动画方案!?!?

The problem is that when I add subviews to myView, to my surprise, they do not follow their superview's animation scheme!?!?

Btw。目前在MyView的initWithFrame中添加了子视图。我尝试将它们的转换属性设置为CGAffineTransformIdentity,但它没有帮助。

Btw. subviews are currently added as usual in MyView's initWithFrame. I tried to set their transform property to CGAffineTransformIdentity bu it did not help.

因此,需要做些什么才能让myView的子视图也能够生成一个很好的动画缩放时尚与超级视角?

So, what needs to be done to allow a subview of myView to also animate in a nice "zoom" fashion together with its superview?

提前致谢!

/ John

Thanks in advance!
/John

推荐答案

我刚遇到同样的问题,解决方案非常简单。修改帧大小只影响当前视图,而不影响子视图(如您所注意到的),转换属性也适用于子视图。

I just ran in to the same problem, and the solution was surprisingly easy. Whereas modifying the frame size only affects the current view, not the subviews (as you noticed), the transform property applies to the subviews as well.

我正在尝试反正你正在做的事情(有一个子视图在显示时显示为放置到现有视图的顶部,而不是从中心缩放)。此代码适用于我:

I'm trying to do the reverse of what you're doing (have a subview that appears to 'drop' on to the top of an existing view when displayed, rather than zoom from the center). This code works for me:

self.transform = CGAffineTransformMakeScale(2,2);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.transform = CGAffineTransformMakeScale(1,1);
self.alpha = 1.0;
[UIView commitAnimations];

在开始动画之前尝试将self.transform设置为CGAffineTransformMakeScale(0,0)并将其设置回提交之前的(1,1)。根本不要修改框架 - 在动画完成后将其保留为视图所需的大小。

Try setting self.transform to CGAffineTransformMakeScale(0,0) before beginning the animation, and set it back to (1,1) before committing. Don't modify the frame at all - leave it at the size you want the view to have after the animation completes.

这篇关于UIView使用子视图开始动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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