我正在CS193P上工作,我想创建一个效果,其中卡片从0,0一个接一个地捕捉到位。我试图链接动画,但一起飞行的意见也是我试图使用UIDynamicAnimator和同样的事情发生。所有的观点都在一起。这是我必须捕捉视图的代码。是否有可能使用UISnapBehavior连续捕捉UIViews
-(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];
}
}
在这种情况下使用它有意义吗?我尝试了几件不同的事情来让卡片一个接一个地飞,但无法完成。
提前致谢!
我以前没用过这个,但是UIDynamicAnimator有一个你可以自己设置的代理。当动态设置达到平衡时,动画设计师(我认为)会暂停并告诉代理它已暂停。所以你不会在这里写一个循环。你拍一张牌,等待暂停,再拍一张牌...... – danh