iOS - 增加部分卷曲点击区域以消除模态

时间:2012-07-06 15:02:44

标签: objective-c ios partial-views modalviewcontroller

有办法做到这一点吗?就像点击屏幕的任何部分一样,可以消除部分模态卷曲。 我想到了一个隐形按钮,但仍然没有覆盖整个卷曲区域。

1 个答案:

答案 0 :(得分: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]];
}