CollectionViewDemoController.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 10
  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.section) \(indexPath.row)"
  18. return cell
  19. }
  20. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  21. guard let identifier = segue.identifier else {
  22. return
  23. }
  24. if identifier == "SettingsNavigationController" {
  25. let controller = segue.destination
  26. controller.modalPresentationStyle = .popover
  27. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  28. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  29. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  30. controller.popoverPresentationController?.delegate = self
  31. }
  32. }
  33. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  34. return .none
  35. }
  36. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  37. self.view.endEditing(true)
  38. }
  39. override var shouldAutorotate: Bool {
  40. return true
  41. }
  42. }