ios - UITap gesture only works on one view -
ios - UITap gesture only works on one view -
i have next code in view controller:
@interface quizcontroller () @property (weak, nonatomic) iboutlet uitextview *questiontext; @property (weak, nonatomic) iboutlet uitextview *one; @property (weak, nonatomic) iboutlet uitextview *two; @property (weak, nonatomic) iboutlet uitextview *three; @property (weak, nonatomic) iboutlet uitextview *four; @property(strong, nonatomic) nsmutablearray* possanswers; @end @implementation quizcontroller - (void)viewdidload { [super viewdidload]; [self.manager setupgame]; self.possanswers = [[nsmutablearray alloc] initwithobjects:@"a", @"b", @"c", @"d", nil]; } //this listens tap on of textviews , sets background bluish - (ibaction)fourtapped:(id)sender { nslog(@"there's been tap!"); [self blankboxes]; if( [sender iskindofclass:[uitapgesturerecognizer class]] ) { uitapgesturerecognizer* tgr = (uitapgesturerecognizer*)sender; uiview* view = tgr.view; if( [view iskindofclass:[uitextview class]]){ uitextview* tv = (uitextview*)view; nslog([tv text]); [tv setbackgroundcolor:[uicolor bluecolor]]; } } } -(void)blankboxes { [_one setbackgroundcolor:[uicolor whitecolor]]; [_two setbackgroundcolor:[uicolor whitecolor]]; [_three setbackgroundcolor:[uicolor whitecolor]]; [_four setbackgroundcolor:[uicolor whitecolor]]; } however, uitextview gets highlighted _one, no matter view tapped. don't understand why is. i'd grateful if point out me.
gesture recognizers attach 1 , 1 view. that's design. if want single gesture recognizer lets recognize taps on multiple views, have attach common, enclosing superview, @ tap coordinates , figure out view tapped.
normally create different gesture recognizer each view needs responds taps.
ios objective-c
Comments
Post a Comment