diff --git a/CHANGELOG.md b/CHANGELOG.md index ca2a172..0bd9288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog + +## 1.6.1 (work in progress) + +- Fix text view inset on `AcknowViewController` (support layout margins, safe area insets) +- Remove support for “readable content guide” on `AcknowViewController` + + ## 1.6 (20 March 2018) - Add tvOS support, by Tobias Tiemerding (@honkmaster) diff --git a/Source/AcknowViewController.swift b/Source/AcknowViewController.swift index b9e47f9..ba9504f 100644 --- a/Source/AcknowViewController.swift +++ b/Source/AcknowViewController.swift @@ -60,6 +60,9 @@ open class AcknowViewController: UIViewController { // MARK: - View lifecycle + let TopBottomDefaultMargin: CGFloat = 20 + let LeftRightDefaultMargin: CGFloat = 10 + /// Called after the controller'€™s view is loaded into memory. open override func viewDidLoad() { super.viewDidLoad() @@ -74,32 +77,35 @@ open class AcknowViewController: UIViewController { view.backgroundColor = UIColor.white #endif + textView.textContainerInset = UIEdgeInsetsMake(TopBottomDefaultMargin, LeftRightDefaultMargin, TopBottomDefaultMargin, LeftRightDefaultMargin) view.addSubview(textView) self.textView = textView - - if #available(iOS 9.0, *) { - textView.translatesAutoresizingMaskIntoConstraints = false - - let marginGuide = view.readableContentGuide - NSLayoutConstraint.activate([ - textView.topAnchor.constraint(equalTo: marginGuide.topAnchor), - textView.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor), - textView.leadingAnchor.constraint(equalTo: marginGuide.leadingAnchor), - textView.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor)]) - } - else { - textView.textContainerInset = UIEdgeInsetsMake(12, 10, 12, 10) - } } /// Called to notify the view controller that its view has just laid out its subviews. open override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + if let textView = textView { + updateTextViewInsets(textView) + } + // Need to set the textView text after the layout is completed, so that the content inset and offset properties can be adjusted automatically. if let acknowledgement = self.acknowledgement { textView?.text = acknowledgement.text } } + + @available(iOS 11.0, *) open override func viewLayoutMarginsDidChange() { + super.viewLayoutMarginsDidChange() + + if let textView = textView { + updateTextViewInsets(textView) + } + } + + func updateTextViewInsets(_ textView: UITextView) { + textView.textContainerInset = UIEdgeInsetsMake(TopBottomDefaultMargin, self.view.layoutMargins.left, TopBottomDefaultMargin, self.view.layoutMargins.right); + } }