Hallo zusammen und ein frohes neues Jahr !
Folgendes Problem bei einem UIScrollView reagiert nicht der touch von meinem Textfield bei einem UIViewController ist das kein Problem
komme grad echt nicht mehr weiter
import UIKit
class NewDoerViewController: UIViewController {
var scrollView = UIScrollView()
var contentView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView = UIScrollView()
self.contentView = UIView()
let navBackgroundImage:UIImage! = UIImage(named: "Bar")
self.navigationController?.navigationBar.setBackgroundImage(navBackgroundImage,
for: .default)
navigationItem.titleView = UIImageView(image: UIImage(named: "Center_little"))
scrollView.backgroundColor = .white
self.scrollView.delegate = self as? UIScrollViewDelegate
self.contentView.isUserInteractionEnabled = true
setupButton()
setupScrollView()
setupViews()
}
func setupScrollView() {
scrollView.translatesAutoresizingMaskIntoConstraints = false
contentView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(scrollView)
self.scrollView.addSubview(contentView)
//x,w,t,b
scrollView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
scrollView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
//x,w,t,b
contentView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor).isActive = true
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
}
func setupViews() {
contentView.addSubview(firstTextfield)
firstTextfield.anchor(top: contentView.topAnchor, left: contentView.leftAnchor, bottom: nil, right: contentView.rightAnchor, paddingTop: 16, paddingLeft: 16, paddingBottom: 0, paddingRight: 16, width: 343, height: 50)
}
func setupButton() {
let settingsButton = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(goBack))
self.navigationItem.leftBarButtonItem = settingsButton
}
let firstTextfield: UITextField = {
let tf = UITextField()
tf.placeholder = "Beruf"
tf.backgroundColor = UIColor(white: 0, alpha: 0.03)
tf.borderStyle = .roundedRect
tf.font = UIFont.systemFont(ofSize: 14)
return tf
}()
@objc func goBack() {
dismiss(animated: true, completion: nil)
}
}
Folgendes Problem bei einem UIScrollView reagiert nicht der touch von meinem Textfield bei einem UIViewController ist das kein Problem
komme grad echt nicht mehr weiter
import UIKit
class NewDoerViewController: UIViewController {
var scrollView = UIScrollView()
var contentView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView = UIScrollView()
self.contentView = UIView()
let navBackgroundImage:UIImage! = UIImage(named: "Bar")
self.navigationController?.navigationBar.setBackgroundImage(navBackgroundImage,
for: .default)
navigationItem.titleView = UIImageView(image: UIImage(named: "Center_little"))
scrollView.backgroundColor = .white
self.scrollView.delegate = self as? UIScrollViewDelegate
self.contentView.isUserInteractionEnabled = true
setupButton()
setupScrollView()
setupViews()
}
func setupScrollView() {
scrollView.translatesAutoresizingMaskIntoConstraints = false
contentView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(scrollView)
self.scrollView.addSubview(contentView)
//x,w,t,b
scrollView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
scrollView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
//x,w,t,b
contentView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor).isActive = true
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true
contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
}
func setupViews() {
contentView.addSubview(firstTextfield)
firstTextfield.anchor(top: contentView.topAnchor, left: contentView.leftAnchor, bottom: nil, right: contentView.rightAnchor, paddingTop: 16, paddingLeft: 16, paddingBottom: 0, paddingRight: 16, width: 343, height: 50)
}
func setupButton() {
let settingsButton = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(goBack))
self.navigationItem.leftBarButtonItem = settingsButton
}
let firstTextfield: UITextField = {
let tf = UITextField()
tf.placeholder = "Beruf"
tf.backgroundColor = UIColor(white: 0, alpha: 0.03)
tf.borderStyle = .roundedRect
tf.font = UIFont.systemFont(ofSize: 14)
return tf
}()
@objc func goBack() {
dismiss(animated: true, completion: nil)
}
}