作者zonble (zonble)
看板MacDev
标题Re: [问题] Interface Builder 动画问题???
时间Mon Dec 28 23:20:35 2009
※ 引述《haman (...)》之铭言:
: ※ 引述《offname (Loafer是了好)》之铭言:
: 不好意思我又来问问题了...
: 如果我想要让这些按钮在移动上有时间差的话
: 应该加上哪些东西???
: 比如说"B"移动了一下以後
: 才换"A"移动
: 还有该如何自己决定它们的移动时间???
: 谢谢
有几种方法
1. 如果是想要自己用时间安排顺序
- (void)myCall
{
// 马上执行
[self method1];
// 2 秒钟之後执行
[self performSelector:@selector(method2) withObject:nil afterDelay:2.0];
}
- (void)method1
{
CGRect newButtonAFrame = CGRectMake(...);
[UIView beginAnimations:nil context:NULL];
buttonA.frame = newButtonAFrame;
[UIView commitAnimations];
}
- (void)method2
{
CGRect newButtonBFrame = CGRectMake(...);
[UIView beginAnimations:nil context:NULL];
buttonB.frame = newButtonBFrame;
[UIView commitAnimations];
}
2. 如果是想要一个动画做完,再做另外一个
- (void)myCall
{
[self method1];
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"animation1"]
&& [finished boolValue]) {
[self method2];
}
}
- (void)method1
{
CGRect newButtonAFrame = CGRectMake(...);
[UIView beginAnimations:@"animation1" context:NULL];
// 在动画结束的时候,我们要呼叫上面那个
// animationDidStop:finished:context
[UIView setAnimationDidStopSelector:(animationDidStop:finished:context)];
buttonA.frame = newButtonAFrame;
[UIView commitAnimations];
}
- (void)method2
{
CGRect newButtonBFrame = CGRectMake(...);
[UIView beginAnimations:@"animation2" context:NULL];
buttonB.frame = newButtonBFrame;
[UIView commitAnimations];
}
在 UIView reference 里头都有说
http://ppt.cc/HQ7a
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.42.199.13
1F:推 haman:谢谢~ :) 12/28 23:31
2F:→ haman:想再问一下 就是我该如何自己设定动画的时间长度??? @ @" 12/28 23:32
3F:→ zonble:+ (void)setAnimationDuration:(NSTimeInterval)duration 12/28 23:37
4F:→ zonble:同样在 UIView reference 里头 12/28 23:40
5F:推 haman:OK 谢谢你~ 我再自己研究看看 12/28 23:42
6F:推 offname:用caanimation的timingFucntions也可以 12/29 18:02