UIViewController+KNSemiModal.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // NSObject+YMOptionsAndDefaults
  3. // Created by YangMeyer on 08.10.12.
  4. // Copyright (c) 2012 Yang Meyer. All rights reserved.
  5. //
  6. @interface NSObject (YMOptionsAndDefaults)
  7. - (void)ym_registerOptions:(NSDictionary *)options
  8. defaults:(NSDictionary *)defaults;
  9. - (id)ym_optionOrDefaultForKey:(NSString*)optionKey;
  10. @end
  11. //==================================================================================================
  12. //
  13. // Convenient category method to find actual ViewController that contains a view
  14. //
  15. @interface UIView (FindUIViewController)
  16. - (UIViewController *) containingViewController;
  17. - (id) traverseResponderChainForUIViewController;
  18. @end
  19. //==================================================================================================
  20. //
  21. // KNSemiModalViewController.h
  22. // KNSemiModalViewController
  23. //
  24. // Created by Kent Nguyen on 2/5/12.
  25. // Copyright (c) 2012 Kent Nguyen. All rights reserved.
  26. //
  27. #define kSemiModalDidShowNotification @"kSemiModalDidShowNotification"
  28. #define kSemiModalDidHideNotification @"kSemiModalDidHideNotification"
  29. #define kSemiModalWasResizedNotification @"kSemiModalWasResizedNotification"
  30. extern const struct KNSemiModalOption {
  31. __unsafe_unretained NSString *traverseParentHierarchy; // boxed BOOL. default is YES.
  32. __unsafe_unretained NSString *pushParentBack; // boxed BOOL. default is YES.
  33. __unsafe_unretained NSString *animationDuration; // boxed double, in seconds. default is 0.5.
  34. __unsafe_unretained NSString *parentAlpha; // boxed float. lower is darker. default is 0.5.
  35. __unsafe_unretained NSString *parentScale; // boxed double default is 0.8
  36. __unsafe_unretained NSString *shadowOpacity; // default is 0.8
  37. __unsafe_unretained NSString *transitionStyle; // boxed NSNumber - one of the KNSemiModalTransitionStyle values.
  38. __unsafe_unretained NSString *disableCancel; // boxed BOOL. default is NO.
  39. __unsafe_unretained NSString *backgroundView; // UIView, custom background.
  40. __unsafe_unretained NSString *disableRotation; // boxed BOOL. default is NO.
  41. } KNSemiModalOptionKeys;
  42. typedef NS_ENUM(NSUInteger, KNSemiModalTransitionStyle) {
  43. KNSemiModalTransitionStyleSlideUp,
  44. KNSemiModalTransitionStyleFadeInOut,
  45. KNSemiModalTransitionStyleFadeIn,
  46. KNSemiModalTransitionStyleFadeOut,
  47. };
  48. typedef void (^KNTransitionCompletionBlock)(void);
  49. @interface UIViewController (KNSemiModal)
  50. /**
  51. Displays a view controller over the receiver, which is "dimmed".
  52. @param vc The view controller to display semi-modally; its view's frame height is used.
  53. @param options See KNSemiModalOptionKeys constants.
  54. @param completion Is called after `-[vc viewDidAppear:]`.
  55. @param dismissBlock Is called when the user dismisses the semi-modal view by tapping the dimmed receiver view.
  56. */
  57. -(void)presentSemiViewController:(UIViewController*)vc
  58. withOptions:(NSDictionary*)options
  59. completion:(KNTransitionCompletionBlock)completion
  60. dismissBlock:(KNTransitionCompletionBlock)dismissBlock;
  61. -(void)presentSemiView:(UIView*)view
  62. withOptions:(NSDictionary*)options
  63. completion:(KNTransitionCompletionBlock)completion;
  64. // Convenient overloading methods
  65. -(void)presentSemiViewController:(UIViewController*)vc;
  66. -(void)presentSemiViewController:(UIViewController*)vc withOptions:(NSDictionary*)options;
  67. -(void)presentSemiView:(UIView*)vc;
  68. -(void)presentSemiView:(UIView*)view withOptions:(NSDictionary*)options;
  69. // Update (refresh) backgroundView
  70. -(void)updateBackground;
  71. // Dismiss & resize
  72. -(void)resizeSemiView:(CGSize)newSize;
  73. -(void)dismissSemiModalView;
  74. -(void)dismissSemiModalViewWithCompletion:(KNTransitionCompletionBlock)completion;
  75. @end