[英]UICollection view cell flip effect
I am making the collection view cell to flip and provide the information about the cell. 我正在使集合视图单元格翻转并提供有关该单元格的信息。
StoryBoard: 故事板:
-Collectionviewcell
-- View1 (tag 100)
-- View2 (tag 200)
code on didSelectItemAtIndexPath . didSelectItemAtIndexPath上的代码。
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
UIView *firstView = (UIView *)[cell viewWithTag:200];
UIView *secondView = (UIView *)[cell viewWithTag:100];
NSString *indexValue = [flipIndex objectAtIndex:indexPath.row];
if (![indexValue isEqualToString:@"1"])
{
[UIView animateWithDuration:1.0 animations:^{
NSLog(@"ANIMATION STARTED");
[UIView transitionFromView:secondView
toView:firstView
duration:2.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
[firstView setHidden:NO];
[secondView setHidden:YES];
}];
}completion:^(BOOL finished) {
NSLog(@"ANIMATION COMPLETED");
}];
[flipIndex removeObjectAtIndex:indexPath.row];
[flipIndex insertObject:@"1" atIndex:indexPath.row];
} else
{
[UIView animateWithDuration:1.0 animations:^{
NSLog(@"ANIMATION STARTED");
[UIView transitionFromView:firstView
toView:secondView
duration:2.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
[secondView setHidden:NO];
[firstView setHidden:YES];
}];
}completion:^(BOOL finished) {
NSLog(@"ANIMATION COMPLETED");
}];
The issue I am facing here is that on first click the view flips from view1 to view 2. On second tap on the view2 the view1 is blank because it is nil. 我在这里面临的问题是,在第一次单击时,视图会从视图1切换到视图2。在第二次点击视图2时,视图1为空,因为它为nil。
Help appreciated. 帮助表示赞赏。
You could subclass UICollectionViewCell with two UIView outlet properties, then hook them up in storyboard. 您可以使用两个UIView插座属性将UICollectionViewCell子类化,然后将其连接到情节提要中。
customCell.view1
customCell.view2
They could then be accessed without relying on tags and neither will be nil, then instead of relying on flipIndex (which is what I think you are doing?) to determine which is showing you could: 然后可以在不依赖标签的情况下访问它们,并且它们都不为零,然后不用依赖flipIndex(我认为您在做什么?)来确定哪些内容可以显示:
if (customCell.view1.hidden) {
//flip to 1
} else {
//flip to 2
}
Remember to reset the views when reusing them however. 但是,在重用视图时,请记住要重置视图。
Try this out: 试试看:
[UIView transitionWithView:cell.contentView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
if (cell.isFirstView) {
cell.isFirstView = NO;
firstView.hidden = NO;
secondView.hidden=YES;
} else {
cell.isFirstView = YES;
firstView.hidden = YES;
secondView.hidden = NO;
}
} completion:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.