gpt4 book ai didi

ios - 如何在基本 VC 中按下按钮时更改容器 View 内容器的框架?

转载 作者:搜寻专家 更新时间:2023-10-31 22:53:12 24 4
gpt4 key购买 nike

我在基础 View Controller 中有一个容器 View 。当 viewWillApear 我更改容器 View 的框架时,它不会出现在屏幕上。在基本 VC 上有一个按钮,按下该按钮时应“调出”之前向下移动的 VC。我怎样才能做到这一点?

我已经尝试在基础 VC 中的按钮的 IBAction 中调用用于更改帧的方法,但是当我这样做时我得到一个 runTimeError:

    @objc func CommentsTapped(_ tap: UITapGestureRecognizer) {
//Bring up the comments view and load all data into it.
UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.9, options: .curveEaseOut, animations: {

self.commentsDelegate!.updateCommentSheet(frame: self.initalFrame.offsetBy(dx: 0, dy: 227))//This method in implemented in the base VC given that it is specified in the protocol for the commentsVC
})
}

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

方法的实现:

class BaseVC: UIViewController, CommentCellDelegate {

@IBOutlet weak var commentsContainer: UIView!

func updateCommentSheet(frame: CGRect) {
commentsContainer.frame = frame
}

最佳答案

基本上,您要做的是:

创建一个 var 并将其设置为等于 prepare 方法中的 ViewController。现在您可以访问并可以从您的基础 View Controller /类控制第二个 View Controller /类。因此,如果您的工作表委托(delegate)设置正确(即 ViewController.xdelegate = self),那么您可以这样调用它:

self.secondVC.xdelegate.updateFrame(frame: newFrame)

关于ios - 如何在基本 VC 中按下按钮时更改容器 View 内容器的框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55736886/

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