2013-03-14 2 views
1

프로젝트에서이 사용자 지정 컨트롤을 구현했습니다. Github page이 컨트롤은 사용하려는 기능을 삭제/완료하기 위해 스 와이프와 같은 사서함을 추가합니다.UITextfield가 스 와이프 동작을 방해합니다.

스토리 보드를 통해 셀에 UITextField를 추가하는 경우에만이 문제가 발생했습니다. 하나를 추가하면 셀이 제스처를 인식하지 못하며 UITextField와 상호 작용할 수있게됩니다.

누구든지이 문제에 대한 해결책이 있습니까?

편집 : 다음은 TableViewCell의 초기화 메소드입니다. 죄송합니다.

- (void)initializer 
{ 
    _mode = MCSwipeTableViewCellModeSwitch; 

    _colorIndicatorView = [[UIView alloc] initWithFrame:self.bounds]; 
    [_colorIndicatorView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; 
    [_colorIndicatorView setBackgroundColor:[UIColor clearColor]]; 
    [self insertSubview:_colorIndicatorView belowSubview:self.contentView]; 

    _slidingImageView = [[UIImageView alloc] init]; 
    [_slidingImageView setContentMode:UIViewContentModeCenter]; 
    [_colorIndicatorView addSubview:_slidingImageView]; 

    _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)]; 
    [self addGestureRecognizer:_panGestureRecognizer]; 
    [_panGestureRecognizer setDelegate:self]; 
} 

- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gesture 
{ 
    UIGestureRecognizerState state   = [gesture state]; 
    CGPoint translation      = [gesture translationInView:self]; 
    CGPoint velocity      = [gesture velocityInView:self]; 
    CGFloat percentage      = [self percentageWithOffset:CGRectGetMinX(self.contentView.frame) relativeToWidth:CGRectGetWidth(self.bounds)]; 
    NSTimeInterval animationDuration  = [self animationDurationWithVelocity:velocity]; 
    _direction = [self directionWithPercentage:percentage]; 

    if (state == UIGestureRecognizerStateBegan) 
    { 
    } 
    else if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStateChanged) 
    { 
     CGPoint center = {self.contentView.center.x + translation.x, self.contentView.center.y}; 
     [self.contentView setCenter:center]; 
     [self animateWithOffset:CGRectGetMinX(self.contentView.frame)]; 
     [gesture setTranslation:CGPointZero inView:self]; 
    } 
    else if (state == UIGestureRecognizerStateEnded || state == UIGestureRecognizerStateCancelled) 
    { 
     _currentImageName = [self imageNameWithPercentage:percentage]; 
     _currentPercentage = percentage; 
     MCSwipeTableViewCellState state = [self stateWithPercentage:percentage]; 

     if (_mode == MCSwipeTableViewCellModeExit && _direction != MCSwipeTableViewCellDirectionCenter && [self validateState:state]) 
      [self moveWithDuration:animationDuration andDirection:_direction]; 
     else 
      [self bounceToOriginWithDirection:_direction]; 
    } 
} 
+0

문제가있는 코드를 게시하거나 사용중인 컨트롤을 만든 사람에게 돌아가서 도움을 요청하십시오. 코드에 문제가 있거나 도움을받을 수있는 경우 도움을 드리려고합니다. –

+0

죄송합니다. 나는 코드를 추가했다. – cherbear

+0

게시 한 코드는 완벽합니다. 그것은 작동해야합니다. 텍스트 필드의 코드는 어디에 있습니까? 스토리 보드를 통해 추가하고 있지만 코드를 연결하고 제스처 이벤트를 시작하기위한 코드는 어디에 있습니까? –

답변

0

이 문제를 해결하는 방법을 알아 낸 제스처를 처리하기위한 방법. 내 프로젝트에 UITextField 하위 클래스를 추가 한 다음 UITextfield 헤더를 사용자 지정 UITableViewCell로 가져 왔습니다. <UITextFieldDelegate>@interface에 추가합니다. UITableViewCell 클래스에 @property (nonatomic, strong, readonly) ItemLabel *label; // ItemLabel being the UITextField class을 추가하고 구현시 종합하십시오.

_label = [[TehdaLabel alloc] initWithFrame:CGRectNull]; 
_label.textColor = [UIColor blackColor]; 
_label.font = [UIFont boldSystemFontOfSize:14]; 
_label.backgroundColor = [UIColor clearColor]; 
_label.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
_label.returnKeyType = UIReturnKeyDone; 
_label.delegate = self; 
[self addSubview:_label]; 

그런 다음 UITextField에 대한 대리자 메서드를 추가 즐거워 : 사용자 지정이없는 경우

그런 다음 사용자 정의 초기화하거나 기본 하나에이 코드를 추가합니다. 마치 셀의 하위보기가 아니기 때문에 UITextField가 간섭하고있는 것처럼 보입니다.

관련 문제