【问题标题】:UICollection view cell flip effectUICollectionviewcell翻转效果
【发布时间】:2015-10-07 13:26:02
【问题描述】:

我正在使集合视图单元格翻转并提供有关单元格的信息。

故事板:

-Collectionviewcell
-- View1 (tag 100)
-- View2 (tag 200)

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");
    }];

我在这里面临的问题是,在第一次单击时,视图会从视图 1 翻转到视图 2。在第二次点击视图 2 时,视图 1 是空白的,因为它是 nil。

帮助表示赞赏。

【问题讨论】:

    标签: ios uicollectionview


    【解决方案1】:

    试试这个:

    [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];
    

    【讨论】:

      【解决方案2】:

      您可以使用两个 UIView 插座属性对 UICollectionViewCell 进行子类化,然后将它们连接到情节提要中。

      customCell.view1
      customCell.view2
      

      然后可以在不依赖标签的情况下访问它们,并且两者都不会是 nil,而不是依赖 flipIndex(我认为你正在做的事情?)来确定哪些显示你可以:

      if (customCell.view1.hidden) {
            //flip to 1
      } else {
            //flip to 2
      }
      

      记住在重用视图时要重置它们。

      【讨论】:

        猜你喜欢
        • 2012-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多