【发布时间】:2013-03-21 04:13:32
【问题描述】:
我正在 iPhone 上创建纸牌游戏。
我的问题是我想在游戏开始时为卡片设置动画,使卡片在套牌中从一个点动画到另一个点。
我在 for 循环中移动我的 UIView 卡片。这就是我的工作
使用此代码,所有卡片一起移动,我需要一个接一个地单独移动卡片
CGPoint point;
// Create the deck of playing cards
for (int i = 0; i < 28; i++) {
CardView *aCardView = [self.mazzo objectAtIndex:i];
point.x = -100;
point.y = 200;
aCardView.center = point;
aCardView.zPosition = i;
[self.viewGioco addSubview:aCardView];
[aCardView release];
//Here i call the method to position the card
[aCardView positionCard];
}
在卡片视图中有这个方法
-(void)positionCard{
[self performSelector:@selector(_positionCard) withObject:nil afterDelay:0.0];
}
-(void)_positionCard{
[UIView beginAnimations:@"posizionacarta" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.3f];
CGPoint point;
point.x = 280 + ((arc4random() % 2) - 1);
point.y = 240 + ((arc4random() % 2) - 1);
self.center = point;
[UIView commitAnimations];
[self setNeedsLayout];
}
【问题讨论】: