【问题标题】:Pop collectionview cell out and zoom - uicollectionviewcell animation弹出 collectionview 单元格并缩放 - uicollectionviewcell 动画
【发布时间】:2016-03-26 08:12:48
【问题描述】:

我试图用我的收藏视图选择创建一个很酷的动画。基本上我有一个显示照片单元的集合视图。我想要发生的是让单元格弹出其位置,缩放并移动到屏幕中心,提示用户确认选择。

到目前为止,这是我的代码,但目前动画采用单元格原始帧位置,所以如果我滚动它并没有考虑到帧位置不再相同。

- (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;
}];
}

【问题讨论】:

    标签: ios objective-c iphone


    【解决方案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) {
    
         }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      相关资源
      最近更新 更多