我正在研究 CS193P,我想创造一种效果,让卡片从 0,0 一个接一个地卡入到位。我试图链接动画,但视图一起飞,我也在尝试使用 UIDynamicAnimator,同样的事情发生了。所有的视图都在捕捉在一起。这是我必须捕捉视图的代码。
-(void)snapCardsForNewGame
{
for (PlayingCardView *cardView in self.cards){
NSUInteger cardViewIndex = [self.cards indexOfObject:cardView];
int cardColumn = (int) cardViewIndex / self.gameCardsGrid.rowCount;
int cardRow = (int) cardViewIndex % self.gameCardsGrid.rowCount;
UISnapBehavior *snapCard = [[UISnapBehavior alloc]initWithItem:cardView snapToPoint:[self.gameCardsGrid centerOfCellAtRow:cardRow inColumn:cardColumn]];
snapCard.damping = 1.0;
[self.animator addBehavior:snapCard];
}
}
-(void)newGame
{
NSUInteger numberOfCardsInPlay = [self.game numberOfCardsInPlay];
for (int i=0; i<numberOfCardsInPlay; i++) {
PlayingCardView *playingCard = [[PlayingCardView alloc]initWithFrame:CGRectMake(0, 0, 50, 75)];
playingCard.faceUp = YES;
[playingCard addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(flipCard:)]];
[self.cards addObject:playingCard];
//NSUInteger cardViewIndex = [self.cards indexOfObject:playingCard];
//int cardColumn = (int) cardViewIndex / self.gameCardsGrid.rowCount;
//int cardRow = (int) cardViewIndex % self.gameCardsGrid.rowCount;
// playingCard.frame = [self.gameCardsGrid frameOfCellAtRow:cardRow inColumn:cardColumn];
playingCard.center = CGPointMake(0, 0);
[self.gameView addSubview:playingCard];
[self snapCardsForNewGame];
}
}
在这种情况下使用它是否有意义?我尝试了几种不同的方法来让卡片一张一张地飞起来,但没能做到。
提前致谢!