uicollectionview navigationcontroller didselectitematindexpath

时间:2014-12-15 09:28:15

标签: ios objective-c uinavigationcontroller uicollectionview uicollectionviewcell

我正在尝试使用UICollectionView为我的应用制作导航网站。当用户点击其中一个单元格时,ViewController应该使用单元格Image的缩放动画来推送另一个单元格。

一切正常,下一个视图显示但问题是:当我调用下一个视图然后导航回我的UICollectionView并再次单击我的单元格时,动画不再显示。 所以我认为ViewController不会调用 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{} 功能了,有点记得了后遗症。但是我怎么告诉他再做动画呢?

以下是segue的代码:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    CostumCollectionCell *theCell =(CostumCollectionCell*)[self.theCollectionView cellForItemAtIndexPath:indexPath];
    UIImageView *overlayer = [[UIImageView alloc]initWithImage:theCell.theImageView.image];
    overlayer.frame=theCell.frame;
    [overlayer setContentMode:UIViewContentModeScaleAspectFill];
    [self.theCollectionView addSubview:overlayer];
    [UIView animateWithDuration:0.75 animations:^{
        overlayer.frame=CGRectMake(theCell.frame.origin.x-theCell.frame.size.width/2, theCell.frame.origin.y-theCell.frame.size.height/2, theCell.frame.size.width*2, theCell.frame.size.height*2);
    } completion:^(BOOL finished) {
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"auditionView"] animated:YES];
                [overlayer removeFromSuperview];
                break;

            default:
                break;
        }
    }];

}

更新代码:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    CostumCollectionCell *theCell =(CostumCollectionCell*)[self.theCollectionView cellForItemAtIndexPath:indexPath];
    [self.overlayer setImage:theCell.theImageView.image];
    self.overlayer.frame=theCell.frame;
    [self.overlayer setHidden:NO];
    [UIView animateWithDuration:0.75 delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.overlayer.frame=CGRectMake(theCell.frame.origin.x-theCell.frame.size.width/2, theCell.frame.origin.y-theCell.frame.size.height/2, theCell.frame.size.width*2, theCell.frame.size.height*2);
    } completion:^(BOOL finished) {
        if(finished){
            switch (indexPath.row) {
                case 0:
                    [self performSegueWithIdentifier:@"auditionSegue" sender:self];
                [self.overlayer setHidden:YES];
                    break;
                default:
                    break;
            }
        }
    }];


}

0 个答案:

没有答案