WYStoryboardPopoverSegue.m 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Version 0.3.9
  3. WYPopoverController is available under the MIT license.
  4. Copyright © 2013 Nicolas CHENG
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  14. INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15. PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  16. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  18. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. #import "WYStoryboardPopoverSegue.h"
  21. ////////////////////////////////////////////////////////////////////////////
  22. @interface WYStoryboardPopoverSegue()
  23. {
  24. WYPopoverController *_popoverController;
  25. id _sender;
  26. WYPopoverArrowDirection _arrowDirections;
  27. WYPopoverAnimationOptions _options;
  28. BOOL _animated;
  29. }
  30. @end
  31. ////////////////////////////////////////////////////////////////////////////
  32. @implementation WYStoryboardPopoverSegue
  33. - (void)perform
  34. {
  35. if ([_sender isKindOfClass:[UIBarButtonItem class]])
  36. {
  37. [_popoverController presentPopoverFromBarButtonItem:(UIBarButtonItem*)_sender
  38. permittedArrowDirections:_arrowDirections
  39. animated:_animated
  40. options:_options];
  41. }
  42. else
  43. {
  44. UIView *view = (UIView *)_sender;
  45. [_popoverController presentPopoverFromRect:view.bounds
  46. inView:view
  47. permittedArrowDirections:_arrowDirections
  48. animated:_animated
  49. options:_options];
  50. }
  51. }
  52. - (WYPopoverController *)popoverControllerWithSender:(id)aSender
  53. permittedArrowDirections:(WYPopoverArrowDirection)aArrowDirections
  54. animated:(BOOL)aAnimated
  55. {
  56. return [self popoverControllerWithSender:aSender
  57. permittedArrowDirections:aArrowDirections
  58. animated:aAnimated
  59. options:WYPopoverAnimationOptionFade];
  60. }
  61. - (WYPopoverController *)popoverControllerWithSender:(id)aSender
  62. permittedArrowDirections:(WYPopoverArrowDirection)aArrowDirections
  63. animated:(BOOL)aAnimated
  64. options:(WYPopoverAnimationOptions)aOptions
  65. {
  66. _sender = aSender;
  67. _arrowDirections = aArrowDirections;
  68. _animated = aAnimated;
  69. _options = aOptions;
  70. _popoverController = [[WYPopoverController alloc] initWithContentViewController:self.destinationViewController];
  71. return _popoverController;
  72. }
  73. - (void)dealloc
  74. {
  75. _sender = nil;
  76. _popoverController = nil;
  77. }
  78. @end