2015-09-26 2 views
0

Я пытаюсь зарегистрировать жест панорамы для UIView, который является подвидным представлением содержимого UITableViewCell. Но действие жеста кастрюли не запускается.Жест жеста не запускается для просмотра внутри содержимого таблицы таблицы

Ниже приведен код распознавателя жестов и ограничений макета.

self.panGesture=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pancontentView:)]; 
self.panGesture.delegate=self; 
[self.mycontentView addGestureRecognizer:self.panGesture]; 
[self.panGesture setCancelsTouchesInView:NO]; 
[self.mainLabel addGestureRecognizer:self.panGesture]; 
self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
self.translatesAutoresizingMaskIntoConstraints=NO; 
if(self) 
{ 
    //self.mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.contentView.frame.origin.x, self.contentView.frame.origin.y, self.contentView.frame.size.width, self.contentView.frame.size.height)]; 
    self.mainLabel=[[UILabel alloc]init]; 
    [self.mainLabel setBackgroundColor:[UIColor greenColor ]]; 
    self.mainLabel.textColor = [UIColor blackColor]; 
    self.mainLabel.font = [UIFont fontWithName:@"Arial" size:12.0f]; 

    self.mycontentView=[[UIView alloc] init]; 
    self.mycontentView.translatesAutoresizingMaskIntoConstraints=NO; 
    self.mainLabel.translatesAutoresizingMaskIntoConstraints=NO; 
    //self.contentView.translatesAutoresizingMaskIntoConstraints=NO; 
    [self.contentView addSubview:self.mycontentView]; 
    [self.mycontentView addSubview:self.mainLabel]; 
    //[self addConstraint:[NSLayoutConstraint constraintWithItem:self.mycontentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]]; 

    [self addConstraints:@[ 
          [NSLayoutConstraint constraintWithItem:self.mainLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], 
          [NSLayoutConstraint constraintWithItem:self.mainLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
          [NSLayoutConstraint constraintWithItem:self.mainLabel attribute: NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:45.0], 
          [NSLayoutConstraint constraintWithItem:self.mainLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-45.0], 

          ]]; 
    [self addConstraints:@[ 
          [NSLayoutConstraint constraintWithItem:self.contentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0], 
          [NSLayoutConstraint constraintWithItem:self.contentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0], 
          [NSLayoutConstraint constraintWithItem:self.contentView attribute: NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0], 
          [NSLayoutConstraint constraintWithItem:self.contentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.mycontentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0], 

          ]]; 
} 

return self; 

Это действие для жесты панды.

switch (gestureRecognizer.state) { 
    case UIGestureRecognizerStateBegan: 
     self.panStartPoint = [gestureRecognizer translationInView:self.contentView]; 
     NSLog(@"Pan Began at %@", NSStringFromCGPoint(self.panStartPoint)); 
     break; 
    case UIGestureRecognizerStateChanged: { 
     CGPoint currentPoint = [gestureRecognizer translationInView:self.contentView]; 
     CGFloat deltaX = currentPoint.x - self.panStartPoint.x; 
     NSLog(@"Pan Moved %f", deltaX); 
    } 
     break; 
    case UIGestureRecognizerStateEnded: 
     NSLog(@"Pan Ended"); 
     break; 
    case UIGestureRecognizerStateCancelled: 
     NSLog(@"Pan Cancelled"); 
     break; 
    default: 
     break; 
} 

Просьба помочь.

ответ

0

Это вопрос свалки. Извините, ребята. Я пытался зарегистрировать жесты перед инициализацией.

Смежные вопросы