gpt4 book ai didi

swift - View 没有动画

转载 作者:行者123 更新时间:2023-11-28 07:06:29 26 4
gpt4 key购买 nike

我有一个 View ,它应该像抽屉一样从屏幕底部向上移动。但它什么都不做。它只是坐在那里 =)谁能告诉我,为什么要这样做?

这是我的代码:

import UIKit

class InfoPopUpVC: UIViewController {
var superView: UIView!
var labelText: String!
let textLabel = UILabel()
let height = CGFloat(80)


override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
UIView.animateWithDuration(0.4, animations: { () -> Void in
self.view.center.y = 50
})
}

override func viewDidLoad() {
super.viewDidLoad()
setupTextLabel()
view.frame = CGRectMake(0, superView.frame.maxY-height, superView.frame.width, height)
AnimationHelper.blurBackgroundForView(view)
view.backgroundColor = .greenColor()
}

func setupTextLabel(){
textLabel.text = labelText
textLabel.frame = CGRectMake(0, 0, view.frame.width, view.frame.height)
textLabel.numberOfLines = 3
textLabel.textAlignment = .Center

textLabel.frame.inset(dx: 10, dy: 8)
textLabel.sizeToFit()
textLabel.font = UIFont(name: "HelveticaNeue-Light", size: 17)
textLabel.textColor = .whiteColor()
view.addSubview(textLabel)
}
}

最佳答案

尝试将您的代码如下放入 viewDidAppear 或 viewWillAppear 中,并使用异步调度。否则你的动画可能无法工作。

 override func viewDidAppear(animated: Bool) {
dispatch_async(dispatch_get_main_queue(), {
UIView.animateWithDuration(0.4, animations: { () -> Void in
self.view.center.y = 50
})
})
}

关于swift - View 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383756/

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