objective c: detect touch began/down when touch started from outside of view/image/button -
i have resembles key pad (one master view, 9 subviews). touch began/down may start in of 9 subviews. detect touch down/began, know when user drags finger other subviews (which views finger dragged into), , when user lifts finger up/touch up/stop.
(stack overflow not letting question posted. i'll try pasting code answer section, see if works).
// in ib set long press gesture min duration 0.1 -(ibaction)handlelongpressonvoices:(uilongpressgesturerecognizer *)gesturerecognizer { cgpoint location = [gesturerecognizer locationinview:gesturerecognizer.view]; if (gesturerecognizer.state == uigesturerecognizerstatebegan){ [self whichvoiceselected:location]; } else if(gesturerecognizer.state == uigesturerecognizerstatechanged){ [self whichvoiceselected:location]; } else if(gesturerecognizer.state == uigesturerecognizerstateended){ [self.avplayer stop]; } }
-(void)whichvoiceselected:(cgpoint)location {
int updatedselectedvoicenumber; if(cgrectcontainspoint(self.voice0.frame, location)){ updatedselectedvoicenumber=0; self.statuslabeloutlet.text = @"..."; }else if(cgrectcontainspoint(self.voice1.frame, location)){ updatedselectedvoicenumber=1; self.statuslabeloutlet.text = @"..."; }else if(cgrectcontainspoint(self.voice2.frame, location)){ updatedselectedvoicenumber=2; self.statuslabeloutlet.text = @"..."; } ...
... }
i found parts of answer across many stackoverflow replies. pasting approach resolving question (a) next person , (b) invitation better solutions.
// in ib set long press gesture min duration 0.1 -(ibaction)handlelongpressonvoices:(uilongpressgesturerecognizer *)gesturerecognizer { cgpoint location = [gesturerecognizer locationinview:gesturerecognizer.view]; if (gesturerecognizer.state == uigesturerecognizerstatebegan){ [self whichvoiceselected:location]; } else if(gesturerecognizer.state == uigesturerecognizerstatechanged){ [self whichvoiceselected:location]; } else if(gesturerecognizer.state == uigesturerecognizerstateended){ [self.avplayer stop]; } } -(void)whichvoiceselected:(cgpoint)location { int updatedselectedvoicenumber; if(cgrectcontainspoint(self.voice0.frame, location)){ updatedselectedvoicenumber=0; self.statuslabeloutlet.text = @"..."; }else if(cgrectcontainspoint(self.voice1.frame, location)){ updatedselectedvoicenumber=1; self.statuslabeloutlet.text = @"..."; }else if(cgrectcontainspoint(self.voice2.frame, location)){ updatedselectedvoicenumber=2; self.statuslabeloutlet.text = @"..."; } ... ... }
Comments
Post a Comment