PopupNavigationController.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // PopupNavigationController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-7-7.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PopupNavigationController.h"
  9. #import "AppDelegate.h"
  10. @interface PopupNavigationController ()
  11. @end
  12. @implementation PopupNavigationController
  13. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  14. {
  15. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  16. if (self) {
  17. // Custom initialization
  18. }
  19. return self;
  20. }
  21. - (void)viewDidLoad
  22. {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handletapPressGesture:)];
  26. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  27. [app.window addGestureRecognizer:tapGesture];
  28. tapGesture.delegate = self;
  29. self.tapGesture = tapGesture;
  30. }
  31. -(void)viewDidDisappear:(BOOL)animated
  32. {
  33. [super viewDidDisappear:animated];
  34. AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  35. [app.window removeGestureRecognizer:self.tapGesture];
  36. }
  37. - (void)didReceiveMemoryWarning
  38. {
  39. [super didReceiveMemoryWarning];
  40. // Dispose of any resources that can be recreated.
  41. }
  42. -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  43. {
  44. // DebugLog(NSStringFromClass([touch.view class]));
  45. if ([NSStringFromClass([touch.view class]) isEqualToString:@"UIDimmingView"]) {//如果当前是tableView
  46. //做自己想做的事
  47. return YES;
  48. }
  49. return NO;
  50. }
  51. -(void)handletapPressGesture:(UITapGestureRecognizer*)sender{
  52. CGPoint point = [sender locationInView:self.view];
  53. if (point.x<self.view.frame.origin.x || point.x >self.view.frame.origin.x+self.view.frame.size.width||point.y<self.view.frame.origin.y||point.y>self.view.frame.origin.y+self.view.frame.size.height) {
  54. [self dismissViewControllerAnimated:YES
  55. completion:^{
  56. //一定要移除手势 否则下次 没有子视图的时候 点击 会崩溃拉
  57. AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  58. [app.window removeGestureRecognizer:sender];
  59. }];
  60. }
  61. }
  62. /*
  63. #pragma mark - Navigation
  64. // In a storyboard-based application, you will often want to do a little preparation before navigation
  65. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  66. {
  67. // Get the new view controller using [segue destinationViewController].
  68. // Pass the selected object to the new view controller.
  69. }
  70. */
  71. @end