简体   繁体   English

addsubview动画只能在第一次使用

[英]addsubview animation works only first time

I am trying add subview with animation effect using the code which work fine for the first time below. 我正在尝试使用下面的代码可以正常工作的代码添加带有动画效果的子视图。

CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionMoveIn; 
transition.subtype = kCATransitionFromRight;

[newView.layer removeAllAnimations]
[newView.layer addAnimation:transition forKey:nil];
[self.masterview addSubview:newView];

There is a back button in newView which removes the View from the superview. newView中有一个后退按钮,可将视图从超级视图中删除。

[newView removeFromSuperview];

Now when I try adding newView as subview again using the above code,its first adds the view as a subview(without animation) and again with animation. 现在,当我尝试使用上述代码再次将newView添加为子视图时,它首先将视图添加为子视图(不包含动画),然后再次添加动画。

Instead of removing newView from superview, why not you can just set a frame like 而不是从超级视图中删除newView,为什么不可以只设置一个框架

newView.frame = CGRectMake(0, -500, CGRectGetWidth(newView.frame), CGRectGetHeight(newView.frame));

so that you can just hide it from showing. 这样您就可以隐藏它,使其不显示。 Just an idea. 只是一个主意。 :-) :-)

When you remove the view from its super view it keeps its frame as it is. 从超级视图中删除视图时,它会保持其框架原样。 So, i think you have to change the newView location to be placed in the new location again. 因此,我认为您必须将newView位置更改为再次放置在新位置。

It will work fine for all the times.But the only difference you have to find is that you need to wai for the duration of animation. 它在任何时候都可以正常工作。但是您唯一要找到的区别是在动画期间需要放弃。 It will not animate continuously. 它不会连续进行动画处理。 It will take a minimum time that you mentioned in the duration. 您将在持续时间内提到最短时间。

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

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