2

これを行う方法はありますか?画面の任意の部分をタップすると、部分的なモーダル カールが解除されます。私は目に見えないボタンを考えましたが、それはまだカール領域全体をカバーしていません.

4

1 に答える 1

1

のメイン ビューにジェスチャ レコグナイザーを追加します。viewDidLoad

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                action:@selector(getDismissed)];

UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                                action:@selector(getDismissed)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
tapRecognizer.delegate = self;
[self.view addGestureRecognizer:tapRecognizer];
[self.view addGestureRecognizer:swipeRecognizer];

-(void)getDismissed
{
    // call dismissViewControllerAnimated:completion: by the presenting view controller
    // you can use delegation or direct call using presentingViewController property
}

次に、解雇をトリガーしたくないという観点から除外します

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    // touching objects of type UIControl will not dismiss the view controller
    return ![touch.view isKindOfClass:[UIControl class]];
}
于 2012-08-05T03:32:58.220 に答える