我正在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