Hide UITableView on touches outside the tableview

前端 未结 3 1396
心在旅途
心在旅途 2021-01-25 00:13

I have a small UITableView that is hidden when the view is loaded. When i click on \"SHOW\" UIButton, the UITableView<

3条回答
  •  粉色の甜心
    2021-01-25 00:44

    You can get touch position by this:

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
    [self.view addGestureRecognizer:singleTap]; 
    
    - (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
     { 
       CGPoint touchPoint=[gesture locationInView:self.View];
     }
    

    Then just check if the point is in tableview frame. If not then hide the tableview. Hope this help. :)

提交回复
热议问题