CollectionViewDemoController.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // CollectionViewDemoController.swift
  3. // IQKeyboardManager
  4. //
  5. // Created by InfoEnum02 on 20/04/15.
  6. // Copyright (c) 2015 Iftekhar. All rights reserved.
  7. //
  8. import UIKit
  9. class CollectionViewDemoController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UIPopoverPresentationControllerDelegate {
  10. @IBOutlet var collectionView: UICollectionView!
  11. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  12. return 20
  13. }
  14. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  15. let cell: UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "TextFieldCollectionViewCell", for: indexPath)
  16. let textField = cell.viewWithTag(10) as? UITextField
  17. textField?.placeholder = "\((indexPath as NSIndexPath).section) \((indexPath as NSIndexPath).row)"
  18. return cell
  19. }
  20. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  21. if let identifier = segue.identifier {
  22. if identifier == "SettingsNavigationController" {
  23. let controller = segue.destination
  24. controller.modalPresentationStyle = .popover
  25. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  26. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  27. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  28. controller.popoverPresentationController?.delegate = self
  29. }
  30. }
  31. }
  32. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  33. return .none
  34. }
  35. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  36. self.view.endEditing(true)
  37. }
  38. override var shouldAutorotate: Bool {
  39. return true
  40. }
  41. }