0
iOS 기기의 메모 앱과 유사한 이미지와 텍스트를 삽입 할 수있는이 게시 기능을 만들려고합니다. 그러나 밝은 회색 영역 (텍스트보기 필드)을 누를 때 키보드가 나타날 때 ScrollView를 이동하거나 크기를 조정하는 방법을 파악할 수 없으므로 회색 영역의 크기가 조정되고 추가 단추가 키보드가 나타납니다. 키보드가 나타나면 ScrollView의 크기를 조정하는 방법?
// PostViewController.swift
//
// Created by Martynas on 09/12/2016.
// Copyright © 2016 Martynas. All rights reserved.
//
import UIKit
import Firebase
class PostViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var ScrollView: UIScrollView!
@IBOutlet var titleTextField: UITextField!
@IBOutlet var contentTextField: UITextView!
@IBOutlet var Menu: UIView!
@IBAction func hideKeyboardWhenSwippedDown(_ sender: Any) {
contentTextField.endEditing(true)
}
override func viewDidLoad() {
super.viewDidLoad()
// Hide keyboard when...
self.hideKeyboardWhenTappedAround() // ...press anywhere outside the keyboard
self.titleTextField.delegate = self
self.contentTextField.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func sendTapped(_ sender: Any) {
if let uid = FIRAuth.auth()?.currentUser?.uid {
if let title = titleTextField.text {
if let content = contentTextField.text {
let postObject: Dictionary<String, Any> = [
"uid": uid,
"title": title,
"content": content
]
FIRDatabase.database().reference().child("posts").childByAutoId().setValue(postObject)
}
}
}
}
@IBAction func addTapped(_ sender: Any) {
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == contentTextField {
ScrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
} else {
return
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
if textField == contentTextField {
ScrollView.setContentOffset(CGPoint(x: 0, y: 250), animated: true)
} else {
return
}
}
// Hide keyboard when user presses 'return' key on the keyboard...
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
titleTextField.resignFirstResponder()
return true
}
}
이
는 컨트롤러보기입니다 : 당신은keyboardDidShow/Hide
통지를 듣고 따라 스크롤 뷰의 높이를 조정해야