how make uiview animated appears right left , having 2 uibuttons on having images on buttons , 1 of them image on button change on button click
you can try code , make changes according requirements . here create baseview moves right left , vice versa. in baseview put whatever u want animate. set bouncedistance,bounceduration,animatewithduration,delay variable according requirement.
-(ibaction)rightclicked:(id)sender { cgrect initalframe = self.baseview.frame; initalframe.origin.x = initalframe.size.width; self.baseview.frame = initalframe; [nstimer scheduledtimerwithtimeinterval:0.1 target:self selector:@selector(movefromleftorright:) userinfo:@0 repeats:no]; } -(ibaction)leftclicked:(id)sender { cgrect initalframe = self.baseview.frame; initalframe.origin.x = -initalframe.size.width; self.baseview.frame = initalframe; [nstimer scheduledtimerwithtimeinterval:0.1 target:self selector:@selector(movefromleftorright:) userinfo:@1 repeats:no]; } -(void)movefromleftorright:(nstimer *) timer { bool isleft = [timer.userinfo boolvalue]; cgfloat bouncedistance = 10; cgfloat bounceduration = 0.2; [uiview animatewithduration:.2 delay:0.0 options:uiviewanimationoptionallowanimatedcontent animations:^{ cgfloat direction = (isleft ? 1 : -1); self.baseview.center = cgpointmake(self.baseview.frame.size.width/2 + direction*bouncedistance, self.baseview.center.y);} completion:^(bool finished){ [uiview animatewithduration:bounceduration animations:^{ self.baseview.center = cgpointmake(self.baseview.frame.size.width/2, self.baseview.center.y); }]; }]; }
Comments
Post a Comment