iOS动画两个视图,彼此堆叠
Posted
技术标签:
【中文标题】iOS动画两个视图,彼此堆叠【英文标题】:iOS Animating two views, stacked on top of each other 【发布时间】:2017-03-24 12:30:41 【问题描述】:我在为两个视图设置动画时遇到问题!
我有两个按钮可以从底部向上滑动不同的视图。
而我想做的是:
我正在像这样为RegisterView
制作动画:
class ViewController: UIViewController
@IBOutlet weak var registerViewHeight: NSLayoutConstraint!
@IBOutlet weak var registerView: UIView!
@IBOutlet weak var registerViewBottomContraint: NSLayoutConstraint!
override func viewDidLoad()
super.viewDidLoad()
self.registerViewBottomContraint.constant = -registerViewHeight.constant
@IBAction func registerButtonPressed(_ sender: AnyObject)
self.registerViewBottomContraint.constant = 0
UIView.animate(withDuration: 0.4, animations:
self.view.layoutIfNeeded()
)
首先:如何正确地将堆叠视图相互叠加? 第二:有没有办法轻松地从按钮转换为视图?
非常感谢:)
【问题讨论】:
【参考方案1】:您可以像这样 [Objective-C] 为视图设置动画:
CGRect viewFrame = self.registerView.frame;
self.registerView.frame = CGRectMake(viewFrame.origin.x, viewFrame.origin.y + viewFrame.size.height, viewFrame.size.width, viewFrame.size.height);
self.registerView.alpha = 0.0;
[UIView animateWithDuration:ANIMATION_DURATION
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^
self. registerView.frame = viewFrame;
self. registerView.alpha = 1.0;
completion:^(BOOL finished)
];
【讨论】:
以上是关于iOS动画两个视图,彼此堆叠的主要内容,如果未能解决你的问题,请参考以下文章