我曾尝试在菜单中上下移动UIButton。我在以下解决方案中遇到的问题是计时器不准确。按钮有时会向上移动122px,有时仅会向上移动120px。我该怎么解决这个问题呢?
-(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];
}发布于 2010-05-04 00:43:10
为什么不使用UIView动画块?
[UIView beginAnimations:nil context:nil];
//Change UIButton frame here
[UIView commitAnimations];在动画块(注释所在的位置)中所做的更改将在commitAnimations之后生成动画。
有关更多选项,请检查类方法:http://tinyurl.com/34y8j5o
https://stackoverflow.com/questions/2759589
复制相似问题