简体   繁体   English

从右向左和从左向内动画视图

[英]Animating View out from right and in from left

I have a view within my view controller that I would like to make it animate leaving the view out from the right side of the screen and then have it animate into the center of the screen from the left side of the screen (To appear that a new view is being brought in with new information on it). 我在视图控制器中有一个视图,希望对其进行动画处理,使视图从屏幕右侧离开,然后使其从屏幕左侧动画化到屏幕中央(以显示引入了具有新信息的新视图)。 I know how to make the view animate out to the right or to the left but I am unsure how to make it go out from the right side and in from the left. 我知道如何使视图向右或向左移动,但是我不确定如何使视图从右侧向左移动。 Any help would be appreciated. 任何帮助,将不胜感激。

On a high level, I would say animate it off screen to the right (you said you know how to do that), then make it hidden and reset its frame to be on the left of your screen, then make it visible and animate it back into view from the left (you also said you know how to do that). 在较高的级别上,我想说说它在屏幕外的右侧动画(您说过知道如何做),然后将其隐藏起来并将其框架重置为屏幕左侧,然后使其可见并对其进行动画处理从左侧回到视图(您还说过,您知道该怎么做)。 You might not even need to hide it...but it feels "safer" to me. 您甚至可能不需要隐藏它...但是对我来说它觉得“更安全”。

In from right 从右进

yourView.frame.origin = CGPoint(x:self.view.frame.size.width, y: yourView.frame.origin.y)
UIView.animate(withDuration: 0.3, animations: {
    yourView.center = CGPoint(x:self.view.center.x, y:self.view.center.y)
}, completion: { (value: Bool) in })

out to left 从左到左

UIView.animate(withDuration: 0.3, animations: {
    yourView.center = CGPoint(x:-yourView.frame.size.width, y:self.view.center.y)
}, completion: { (value: Bool) in })

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

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