【问题标题】:UICollectionView cell didselect flip animation, View is missingUICollectionView 单元格没有选择翻转动画,视图丢失
【发布时间】:2014-11-12 05:34:12
【问题描述】:
didSelect 方法上的 UICollectionView 单元格翻转动画应该与单击的索引单元格的详细信息一起翻转,如果用户想要转到原始视图,应该能够在单元格上看到。
我正在使用
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:1.0
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^
{
[UIView transitionFromView:cell.contentView
toView:cell.contentView
duration:.5
options:UIViewAnimationOptionTransitionFlipFromRight
completion:nil];
}
completion:^(BOOL finished)
{
}
];
【问题讨论】:
标签:
ios
animation
uicollectionview
【解决方案1】:
在您的代码中,动画将您从视图中移除并显示到视图中。因此,在集合中,如果内容视图被移除,那么它是如何返回的。
所以,不要删除视图,只需隐藏它。
请使用以下代码
CVCell* cell1 = (CVCell *)[collectionView cellForItemAtIndexPath:indexPath];
[UIView transitionWithView:cell1.contentView
duration:5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
if (cell1.isred) {
cell1.isred = NO;
cell1.greenview.hidden = NO;
cell1.redView.hidden=YES;
} else {
cell1.isred = YES;
cell1.greenview.hidden = YES;
cell1.redView.hidden=NO;
}
} completion:nil];
greenview 是第一个视图,redview 是第二个添加到单元格上的视图。
现在,当翻转第一个 greenview 时,会显示 redview 并隐藏 redview,下一次反之亦然
你可以试试其他动画
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 2.6f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.startProgress = 0.1;
animation.endProgress = 1.0;
animation.removedOnCompletion = YES;
animation.type = @"cube";//---
animation.subtype = (cell1.isred)?kCATransitionFromLeft:kCATransitionFromRight;
[CATransaction setCompletionBlock:^{
if (cell1.isred) {
cell1.isred = NO;
cell1.greenview.hidden = NO;
cell1.redView.hidden=YES;
} else {
cell1.isred = YES;
cell1.greenview.hidden = YES;
cell1.redView.hidden=NO;
}
}];
[cell1.contentView.layer addAnimation:animation forKey:@"Cameraanimation"];