gpt4 book ai didi

ios - 如何使用 swift 在 ios 的 ScrollView 下滚动特定 View ?

转载 作者:搜寻专家 更新时间:2023-11-01 06:55:36 25 4
gpt4 key购买 nike

我的 View 如下所示,75% 的 View 是 ScrollView ,25% 的 View 是底部 ImageView 。

enter image description here

在 ScrollView 中的 subview

enter image description here

我的屏幕用户界面

enter image description here

我也试过下面的代码,但没有用

  @IBOutlet weak var Scrollview: UIScrollView!

override func viewDidLoad() {
super.viewDidLoad()

Scrollview.contentSize.height = 1000

}

Now when keyboard is open I am not able to click Create Button..I want to make scroll child view only under the Scrollview..I want to keep my Image in the Bottom fixed.Android I have done..please anyone help me I am new to iOS...

最佳答案

您可以使用 NotificationCenter 在键盘打开时接收通知。将此代码添加到您的 viewDidLoad() 方法中:

NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillShow, object: nil, queue: nil) { (notification) in
let keyboardHeight = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0.0

Scrollview.contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardHeight, right: 0.0)
}


现在您应该可以滚动直到看到 Create Button

注意:您必须调整键盘高度值才能将正确的插图添加到您的Scrollview(在您的情况下减去imageView键盘高度值的高度)。否则,您将向 ScrollView 添加过多的插图。

关于ios - 如何使用 swift 在 ios 的 ScrollView 下滚动特定 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53593562/

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