gpt4 book ai didi

iOS 动画两个 View ,彼此堆叠

转载 作者:行者123 更新时间:2023-11-30 12:34:58 25 4
gpt4 key购买 nike

我在为两个 View 设置动画时遇到问题!

我有两个按钮,它们将从底部向上滑动不同的 View 。

我想做的事情是:

screenshot

我正在像这样设置 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()
})

}

第一:如何正确地将堆叠 View 添加到彼此之上?第二:有没有办法轻松地从按钮到 View 的转换?

非常感谢:)

最佳答案

您可以像这样为 View 设置动画 [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 动画两个 View ,彼此堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42999568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com