2016-03-26 20 views
2

私のコレクションビュー選択でクールなアニメーションを作成しようとしています。基本的に私はフォトセルのコレクションビューを表示しています。私がしたいのは、セルがその場所から飛び出して、画面の中央に移動して、選択を確認するように促されます。ポップコレクションビューセルアウトとズーム - uicollectionviewcellアニメーション

これまでのコードですが、現在のところアニメーションはセルの元のフレーム位置をとるため、スクロールするとフレーム位置が同じではないことが考慮されます。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ 

PhotoCell *cell = (PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath]; 
collectionView.allowsSelection = NO; 
[self createAnimationWithCell:cell]; 

} 

- (void)createAnimationWithCell:(PhotoCell *)cell { 

UIImageView *selectedImage = [[UIImageView alloc] initWithFrame:cell.bounds]; 
selectedImage.center = cell.center; 
selectedImage.image = cell.imageView.image; 
[self.view addSubview:selectedImage]; 

[UIView animateWithDuration:2.5 animations:^{ 
    selectedImage.center = self.view.center; 
} completion:^(BOOL finished) { 
    [selectedImage removeFromSuperview]; 
    self.collectionView.allowsSelection = YES; 
}]; 
} 

答えて

1

私はそれを自分で解決:

を同じ問題を経験している人のために、我々は、コレクションビューがスクロールしているどのくらい考慮して(オフセット)し、その情報を使用する必要があります。私はcollectionViewOffsetという変数を作成し、それをその後、使用0.0

の初期値を与えた:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    // getting the scroll offset 
    collectionViewOffset = scrollView.contentOffset.y; 
    NSLog(@"offset: %f", collectionViewOffset); 
} 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ 

     PhotoCell *cell = (PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath]; 
     //collectionView.allowsSelection = NO; 
     //collectionView.scrollEnabled = NO; 

    [cell.superview bringSubviewToFront:cell]; 
    [UIView animateWithDuration:2.0 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:.2 options:UIViewAnimationOptionCurveLinear animations:^{ 
    cell.center = CGPointMake(self.view.vWidth/2, self.bannerView.vBottomEdge + collectionViewOffset + 40); 
    } completion:^(BOOL finished) { 

    }]; 
} 
関連する問題