ScrollViewController.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // ScrollViewController.swift
  3. // IQKeyboard
  4. //
  5. // Created by Iftekhar on 23/09/14.
  6. // Copyright (c) 2014 Iftekhar. All rights reserved.
  7. //
  8. import UIKit
  9. class ScrollViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate, UIPopoverPresentationControllerDelegate {
  10. @IBOutlet var scrollViewDemo: UIScrollView!
  11. @IBOutlet var simpleTableView: UITableView!
  12. @IBOutlet var scrollViewOfTableViews: UIScrollView!
  13. @IBOutlet var tableViewInsideScrollView: UITableView!
  14. @IBOutlet var scrollViewInsideScrollView: UIScrollView!
  15. @IBOutlet var topTextField: UITextField!
  16. @IBOutlet var bottomTextField: UITextField!
  17. @IBOutlet var topTextView: UITextView!
  18. @IBOutlet var bottomTextView: UITextView!
  19. deinit {
  20. topTextField = nil
  21. bottomTextField = nil
  22. topTextView = nil
  23. bottomTextView = nil
  24. }
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. }
  28. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  29. return 5
  30. }
  31. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  32. let identifier = "\(indexPath.section) \(indexPath.row)"
  33. var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
  34. if cell == nil {
  35. cell = UITableViewCell(style: .default, reuseIdentifier: identifier)
  36. cell?.selectionStyle = .none
  37. cell?.backgroundColor = UIColor.clear
  38. let textField = UITextField(frame: cell!.contentView.bounds.insetBy(dx: 5, dy: 5))
  39. textField.autoresizingMask = [.flexibleBottomMargin, .flexibleTopMargin, .flexibleWidth]
  40. textField.placeholder = identifier
  41. textField.borderStyle = .roundedRect
  42. cell?.contentView.addSubview(textField)
  43. }
  44. return cell!
  45. }
  46. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  47. guard let identifier = segue.identifier else {
  48. return
  49. }
  50. if identifier == "SettingsNavigationController" {
  51. let controller = segue.destination
  52. controller.modalPresentationStyle = .popover
  53. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  54. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  55. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  56. controller.popoverPresentationController?.delegate = self
  57. }
  58. }
  59. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  60. return .none
  61. }
  62. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  63. self.view.endEditing(true)
  64. }
  65. override var shouldAutorotate: Bool {
  66. return true
  67. }
  68. }