내가 매트를 선호하는 동안 :
#import <UIKit/UIGestureRecognizerSubclass.h>
@interface MyTapGestureRecognizer : UITapGestureRecognizer
@property (nonatomic, strong) NSMutableArray *excludedViews;
@end
@implementation MyTapGestureRecognizer
@synthesize excludedViews = _excludedViews;
- (id)initWithTarget:(id)target action:(SEL)action
{
self = [super initWithTarget:target action:action];
if (self)
{
_excludedViews = [[NSMutableArray alloc] init];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
CGPoint location = [[touches anyObject] locationInView:self.view];
for (UIView *excludedView in self.excludedViews)
{
CGRect frame = [self.view convertRect:excludedView.frame fromView:excludedView.superview];
if (CGRectContainsPoint(frame, location))
self.state = UIGestureRecognizerStateFailed;
}
}
@end
와 다음, 당신이 그것을 사용할 때, 당신이 제외 할 내용을 제어 지정 Meyer의 제안이나 커스텀 제스처 인식기를 사용하는 또 다른 제안인데, 맞춤식 제스처 인식기를 사용하지 않는 또 다른 해결책은 탭 제스처 인식기가 테이블 뷰의 셀을 탭했는지 여부를 확인하는 것입니다. 그렇다면 수동으로 didSelectRowAtIndexPath
을 호출하십시오. :
테이블 뷰와 관련하여 정교한 작업을 수행하는 경우 (예 : 셀 편집, 사용자 정의 컨트롤 등)을 사용하면 해당 동작을 잃지 만, 단지 didSelectRowAtIndexPath
을 수신하려는 경우이 작업이 필요할 수 있습니다. 다른 두 가지 접근법 (개별 뷰 또는 사용자 정의 제스처 인식기)을 사용하면 전체 테이블 뷰 기능을 유지할 수 있지만 단순한 무언가가 필요하고 나머지 테이블 뷰의 기본 제공 기능이 필요하지 않은 경우이 기능이 작동합니다.
출처
2012-08-13 15:18:09
Rob
tableview는 화면에서 유일한보기입니까, 아니면 계층 구조의 일부입니까? –
답변 해 주셔서 감사합니다. 아니요, tableview 및 UIToolbar가 화면의 subView입니다. – Gopinath
어떻게 작동합니까? tapgesturerecognizer는 언제해야합니까? –