ios - What to use in order to run code once screen is tapped? -
i working on game in xcode object bouncing , forth across screen. need run code stop object moving once user taps anywhere on screen. don't want use button although could. new , don't understand need use in order run code once user taps screen. please tell me use , explain does.
code:
#import "game.h" @interface game () @end @implementation game -(ibaction)play:(id)sender{ shaketimer = [nstimer scheduledtimerwithtimeinterval:.01 target:self selector:@selector(shake) userinfo:nil repeats:no]; play.hidden = yes;} -(void)shake{ cabasicanimation *shake = [cabasicanimation animationwithkeypath:@"position"]; [shake setduration:1]; [shake setrepeatcount:infinity]; [shake setautoreverses:yes]; [shake setfromvalue:[nsvalue valuewithcgpoint: cgpointmake(piece.center.x - 5,piece.center.y)]]; [shake settovalue:[nsvalue valuewithcgpoint: cgpointmake(piece.center.x + 300, piece.center.y)]]; [piece.layer addanimation:shake forkey:@"position"]; uitapgesturerecognizer *taps= [[ uitapgesturerecognizer alloc] initwithtarget:self action: @selector(shoot)]; taps.numberoftouchesrequired = 1; taps.numberoftouchesrequired =1; [self. addgesturerecognizer:taps]; } -(void)shoot{ [shaketimer invalidate]; } - (void)viewdidload{ leave.hidden = yes;} -(void)gameover{ leave.hidden = no; [piecemovement invalidate]; } @end
these methods may override in uiview subclass:
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event; - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event; - (void)touchesended:(nsset *)touches withevent:(uievent *)event; - (void)touchescancelled:(nsset *)touches withevent:(uievent *)event
Comments
Post a Comment