i trying register pan gesture uiview subview of content view of uitableviewcell .but pan gesture action not fired.
below code pan gesture recognizer , layout constraints.
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;
this action pan gesture.
switch (gesturerecognizer.state) { case uigesturerecognizerstatebegan: self.panstartpoint = [gesturerecognizer translationinview:self.contentview]; nslog(@"pan began @ %@", 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; }
please help.
that dump question. sorry guys. trying register gestures before initializing .
Comments
Post a Comment