我需要帮助来实现这个目标:
我正试图创造这个,这是我到目前为止的结果。由于点击后按钮图片显示,我仍然无法创建任何内容:
我的结果
正如你在按下按钮时在gif中看到的那样, UIView height constraint.constant 被设置为更高的值并且UIView变得更高。我想要的只是剥离背景以获得更高。
这是视图在IB中的处理方式。
最后,这就是我编码的方式
class LetterScreenViewController: UIViewController, ResizeWordViewDelegate {
@IBOutlet weak var youTubeView: YouTubeView!
@IBOutlet weak var phonemeView: PhonemeView!
@IBOutlet weak var wordView: WordView!
var letterPresenter: LetterPresenter?
@IBOutlet weak var heightWordViewConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
delegateWordObj()
if let presenter = letterPresenter {
presenter.setupView()
}
}
@IBAction func dismissLetter(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
func delegateWordObj() {
wordView.resizeWordViewDelegate = self
}
func didPressButton() {
if heightWordViewConstraint.constant <= 0 {
heightWordViewConstraint.constant = 30
}else{
heightWordViewConstraint.constant = 0
}
}
}
import UIKit
protocol ResizeWordViewDelegate {
func didPressButton()
}
class WordView: UIView {
@IBOutlet weak var backgroundListras: UIImageView!
@IBOutlet var WordView: UIView!
@IBOutlet weak var showWordButton: UIButton!
var resizeWordViewDelegate: ResizeWordViewDelegate!
override init(frame: CGRect) {
super.init(frame: frame)
xibInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibInit()
}
func xibInit() {
Bundle.main.loadNibNamed("WordView", owner: self, options: nil)
addSubview(WordView)
WordView.frame = self.bounds
WordView.round(corners: [.topLeft,.topRight], radius: 120)
WordView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
@IBAction func showWordButtonAction(_ sender: Any) {
resizeWordViewDelegate.didPressButton()
self.frame.size = CGSize(width: 375, height: 200)
self.backgroundListras.frame.size = CGSize(width: 375, height: 200)
}
}
我想知道一种方法来调整此UIView的所有内容。找到增加高度的解决方案后,我可以在按下按钮时显示所有其他组件。
答案 0 :(得分:0)
我相信你的目标是创造这样的东西:
我所要做的就是以编程方式更改约束的高度
检查以下项目中的解决方案:
https://gitlab.com/DanielLimaDF/ResizeTest.git
重要提示:注意addSubview,如果在调用addSubview之前创建了约束,它可以从View中删除约束