ViewController.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // ViewController.swift
  3. // swift test
  4. //
  5. // Created by Iftekhar on 22/09/14.
  6. // Copyright (c) 2014 Iftekhar. All rights reserved.
  7. //
  8. import UIKit
  9. import IQKeyboardManagerSwift
  10. class ViewController: UITableViewController, UIPopoverPresentationControllerDelegate {
  11. @IBAction func shareClicked (_ sender: UIBarButtonItem) {
  12. let shareString: String = "IQKeyboardManager is really great control for iOS developer to manage keyboard-textField."
  13. let shareImage: UIImage = UIImage(named: "IQKeyboardManagerScreenshot")!
  14. let youtubeUrl: URL = URL(string: "http://youtu.be/6nhLw6hju2A")!
  15. var activityItems = [Any]()
  16. activityItems.append(shareString)
  17. activityItems.append(shareImage)
  18. activityItems.append(youtubeUrl)
  19. let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
  20. controller.excludedActivityTypes = [.print, .copyToPasteboard, .assignToContact, .saveToCameraRoll]
  21. present(controller, animated: true) { () -> Void in
  22. }
  23. }
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. IQKeyboardManager.shared.toolbarManageBehaviour = IQAutoToolbarManageBehaviour.byPosition
  27. // Do any additional setup after loading the view, typically from a nib.
  28. }
  29. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  30. tableView.deselectRow(at: indexPath, animated: true)
  31. }
  32. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  33. guard let identifier = segue.identifier else {
  34. return
  35. }
  36. if identifier == "SettingsNavigationController" {
  37. let controller = segue.destination
  38. controller.modalPresentationStyle = .popover
  39. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  40. controller.popoverPresentationController?.sourceView = sender as? UIView
  41. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  42. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  43. controller.popoverPresentationController?.delegate = self
  44. } else if identifier == "PopoverViewController" {
  45. let controller = segue.destination
  46. controller.modalPresentationStyle = .popover
  47. controller.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
  48. controller.popoverPresentationController?.sourceView = sender as? UIView
  49. let heightWidth = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
  50. controller.preferredContentSize = CGSize(width: heightWidth, height: heightWidth)
  51. controller.popoverPresentationController?.delegate = self
  52. }
  53. }
  54. func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
  55. return .none
  56. }
  57. func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
  58. self.view.endEditing(true)
  59. }
  60. override var shouldAutorotate: Bool {
  61. return true
  62. }
  63. }