2012-07-06 18 views

回答

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]]; 
} 
+0

謝謝排除。我很久以前需要這個。但我期待下一次使用。 ;) – Milad 2012-10-07 06:48:32