如何使用Swift在iOS的滚动视图下滚动特定的视图?

时间:2018-12-03 12:08:19

标签: ios swift storyboard

我的视图低于75%,其中Scrollview和25%是Bottom Imageview。

enter image description here

childView位于滚动视图中

enter image description here

我的屏幕界面

enter image description here

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

  @IBOutlet weak var Scrollview: UIScrollView!

  override func viewDidLoad() {
        super.viewDidLoad()

    Scrollview.contentSize.height = 1000

  }
  

现在,当键盘打开时,我无法单击创建按钮。   想要仅在scroll下制作Scrollview子视图。   将我的图片固定在底部。Android我已经完成了..请   有人帮我,我是iOS的新手...

2 个答案:

答案 0 :(得分:2)

You can make use of NotificationCenter to receive a notification when the keyboard is open. Add this code into your viewDidLoad() method:

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)
}


Now you should be able to scroll until you see Create Button.

Note: You will have to adjust the keyboard height value in order to add the correct inset to your Scrollview (in your case subtract the imageView height from the keyboard height value). If not you will add too much inset to the scroll view.

答案 1 :(得分:0)

Try this library it will definitely solve your problem

Link - https://github.com/michaeltyson/TPKeyboardAvoiding