I've tried to move a UIButton up and down in a menu. The problem I've got with the following solution is that the timer is not accurate. Sometimes the Button is moved up 122px, sometimes only 120px. How I can fix this?
-(IBAction)marketTabClicked:(id)sender {
if (marketTabExtended) {
NSLog(@"marketTabExtended = YES");
return;
}
else {
if (iPhoneAppsExtended) {
timer = [NSTimer scheduledTimerWithTimeInterval:0.005 target: self selector: @selector(animateItemApps) userInfo: nil repeats: YES];
}
else {
if (homepageExtended) {
timer = [NSTimer scheduledTimerWithTimeInterval:0.005 target: self selector: @selector(animateItemHomepage) userInfo: nil repeats: YES];
}
else {
timer = [NSTimer scheduledTimerWithTimeInterval:0.005 target: self selector: @selector(animateItemMarketing) userInfo: nil repeats: YES];
}
}
}
[self performSelector:@selector(stopTimer) withObject:self afterDelay:0.605];
iPhoneAppsExtended = NO;
homepageExtended = NO;
marketTabExtended = NO;
marketTabExtended = YES;
}
-(void)animateItemApps {
CGPoint movement;
movement = CGPointMake(0, -1);
homepage.center = CGPointMake(homepage.center.x, homepage.center.y + movement.y);
}
-(void)animateItemHomepage {
CGPoint movement;
movement = CGPointMake(0, 1);
homepage.center = CGPointMake(homepage.center.x, homepage.center.y + movement.y);
//marketTab.center = CGPointMake(marketTab.center.x, marketTab.center.y + movement.y);
}
-(void)animateItemMarketing {
CGPoint movement;
movement = CGPointMake(0, -1);
//marketTab.center = CGPointMake(marketTab.center.x, marketTab.center.y + movement.y);
homepage.center = CGPointMake(homepage.center.x, homepage.center.y + movement.y);
}
-(void)stopTimer {
[timer invalidate];
}