移动UIButton [英] Moving UIButton around
本文介绍了移动UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在菜单中上下移动UIButton。
我用以下解决方案得到的问题是计时器不准确。有时Button会向上移动122px,有时仅为120px。我如何解决这个问题?
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];
}
推荐答案
你为什么不用UIView动画块?
Why don't you use UIView animation blocks?
[UIView beginAnimations:nil context:nil];
//Change UIButton frame here
[UIView commitAnimations];
动画块(评论所在位置)所做的更改将在<$ c $之后生成动画c> commitAnimations 。
Changes made in the animation block (where the comment is), will be animated after commitAnimations
.
检查类mathods以获取更多选项: http://tinyurl.com/34y8j5o
Check the class mathods for more options: http://tinyurl.com/34y8j5o
这篇关于移动UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文