2015-09-26 83 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

这是一个转储问题。 对不起。 我试图在初始化之前注册的手势。