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

标签 ios swift storyboard

我的 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/

相关文章:

ios - 为什么 UIImageView 没有使用 Swift 正确加载

ios - Oauth2 facebook 回调 swift

ios - Touch Up Inside 的全局事件处理程序

swift - 这个语法在 Swift 中是什么意思?

ios - 如何使用 Storyboard在 viewController 中制作多个 View

iOS MKMapView 不在模拟器中显示 map

ios - Swift 4 - AVAudioPlayer 从 UISlider 设置 currentTime

json - 从服务器提取数据数组期间,类型 "Any"在 Swift 3 中没有下标成员

ios - 在构建选项卡式界面时,我可以避免多余的 segues 吗?

ios - JASidepanels 不显示导航按钮