iphone - How to detect both main view UILongPressGestureRecognizer and subview UIPanGestureRecognizer -


i encountered problem uilongpressgesturerecognizer , uipangesturerecognizer.

i wish long press in self.view add view uipangesturerecognizer in self.view.

however uipangesturerecognizer not recognizing.

did missed ?

- (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.     //[self initimagesandgesture];      uilongpressgesturerecognizer *taprecognizer = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(addimgview:)];     taprecognizer.numberoftouchesrequired = 1;     taprecognizer.minimumpressduration = 0.7;     [taprecognizer setdelegate:self];     self.view.userinteractionenabled = yes;      [self.view addgesturerecognizer:taprecognizer];    }  -(void)addimgview:(uilongpressgesturerecognizer *)recognizer {     nslog(@"tappppp");      if(uigesturerecognizerstatebegan == recognizer.state) {         // called on start of gesture, work here          nslog(@"uigesturerecognizerstatebegan");         uiimage *img = [uiimage imagenamed:@"beer.png"];         uiimageview *imgview = [[uiimageview alloc]initwithimage:img];          uilabel *timestamp = [[uilabel alloc]initwithframe:cgrectmake(0, 0, 30, 30)];         timestamp.text = [nsstring stringwithformat:@"%f",[nsdate date]];          uiview *drinkview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 50, 50)];         [drinkview setuserinteractionenabled:yes];          cgpoint taplocation = [recognizer locationinview:recognizer.view];          [timestamp setcenter:cgpointmake(taplocation.x, taplocation.y)];         [imgview setcenter:cgpointmake(taplocation.x,taplocation.y)];          [drinkview addsubview:imgview];         [drinkview addsubview:timestamp];          [drinkview setuserinteractionenabled:yes];          [imgview setuserinteractionenabled:yes];         [timestamp setuserinteractionenabled:yes];          uipangesturerecognizer *recognizer1 = [[uipangesturerecognizer alloc]initwithtarget:self action:@selector(handlepan1:)];         [recognizer1 setdelegate:self];         [drinkview addgesturerecognizer:recognizer1];         [self.view addsubview:drinkview];      }  } 

-(void)addimgview:(uilongpressgesturerecognizer *)recognizer {     nslog(@"tappppp");      if(uigesturerecognizerstatebegan == recognizer.state) {         // called on start of gesture, work here          nslog(@"uigesturerecognizerstatebegan");         uiimage *img = [uiimage imagenamed:@"beer.png"];         uiimageview *imgview = [[uiimageview alloc]initwithimage:img];          uilabel *timestamp = [[uilabel alloc]initwithframe:cgrectmake(0, 0, 150, 30)];         timestamp.text = [nsstring stringwithformat:@"%f",[nsdate date]];          uiview *drinkview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 75,115)];         drinkview.backgroundcolor=[uicolor redcolor];         [drinkview setuserinteractionenabled:yes];          cgpoint taplocation = [recognizer locationinview:recognizer.view];          [drinkview setcenter:cgpointmake(taplocation.x,taplocation.y)];            [drinkview setuserinteractionenabled:yes];        [imgview setuserinteractionenabled:yes];         [timestamp setuserinteractionenabled:yes];          [drinkview addsubview:imgview];         [drinkview addsubview:timestamp];           uipangesturerecognizer *recognizer1 = [[uipangesturerecognizer alloc]initwithtarget:self action:@selector(handlepan1:)];         [recognizer1 setdelegate:self];         [drinkview addgesturerecognizer:recognizer1];           [self.view addsubview:drinkview];      }      if(uigesturerecognizerstatechanged == recognizer.state) {         // repeated work here (repeats continuously) while finger down         nslog(@"uigesturerecognizerstatechanged");      }      if(uigesturerecognizerstateended == recognizer.state) {         // end work here when finger lifted         nslog(@"uigesturerecognizerstateended");      } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -