0

如何通过按屏幕上除 UIAction 表之外的任何位置来使 UIActionSheet 消失。这是我尝试实现目前不起作用的代码

- (void) viewDidAppear:(BOOL)animated
{
    [paintingVIew becomeFirstResponder];
    [super viewWillAppear:animated]; // or viewDidAppear?

    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
    [recognizer setNumberOfTapsRequired:1];
     recognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
    [self.view.window addGestureRecognizer:recognizer];
}



 - (void)handleTapBehind:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded)
    {
        CGPoint location = [sender locationInView:nil]; //Passing nil gives us coordinates in the window

    //Then we convert the tap's location into the local view's coordinate system, and test to see if it's in or outside. If outside, dismiss the view.

        if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil])
        {
            // Remove the recognizer first so it's view.window is valid.
            [self.view.window removeGestureRecognizer:sender];
            [self dismissModalViewControllerAnimated:YES];
        }
    }
}
4

1 回答 1

0

AUIActionSheet是模态的,这意味着在显示操作表时任何底层视图都不会收到触摸(就像 a 一样UIAlertView)。所以,回答你的问题:你不能用 default 做到这一点UIActionSheet

于 2013-02-02T07:25:57.920 回答