Ultravisual iOS应用程序,如使用UICollectionViewLayout的动画,不会重叠图像

Gau*_*ana 7 objective-c uiviewanimation ios parallax uicollectionviewlayout

我创建了当前在UltraVisualiOS应用程序中可用的相同组件,用于查看动画中的记录,如parallax效果.有关详细信息,请参阅以下附加的GIF图像.我想要与给定视频网址相同的动画.

为此,我发现两个GitHub URL几乎相同,但它不符合UltraVisualiOS应用程序中使用的相同动画.有关更多信息,请查找以下两个网址.

网址:https
://github.com/fdzsergio/SFFocusViewLayout/tree/2.0.0网址:https://github.com/RobotsAndPencils/RPSlidingMenu

问题:
现在我正面临着如何缩小聚焦图像的问题,考虑到底部保持静止.第一个聚焦图像应从顶部缩小(底部保持静止),同时考虑到保持静止的第二个图像的顶部,下一个图像将聚焦.

现行代码:

- (void)prepareLayout {

NSMutableArray *cache = [NSMutableArray array];

NSInteger numberOfItems = [self.collectionView numberOfItemsInSection:0];

// last rect will be used to calculate frames past the first one.  We initialize it to a non junk 0 value
CGRect frame = CGRectZero;
CGFloat y = 0;
CGFloat footerTop = 0;

for (NSUInteger item = 0; item < numberOfItems; item++) {
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0];
    UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]
    ;
    // Important because each cell has to slide over the top of the previous one
    attributes.zIndex = item;

    // Initially set the height of the cell to the standard height
    CGFloat height = self.standardHeight;

    if (indexPath.item == self.currentFocusedItemIndex) {
        // The featured cell
        CGFloat yOffset = self.standardHeight * self.nextItemPercentageOffset;
        y = self.collectionView.contentOffset.y - yOffset;
        //y = yOffset - self.standardHeight * self.nextItemPercentageOffset;

        height = self.focusedHeight;

        //*********CURRENTLY WORKING ON THIS LINE TO ACHIEVE THE REQUIRED ANIMATION ******************
        //attributes.transform = CGAffineTransformTranslate(attributes.transform, 0, -self.collectionView.contentOffset.y+self.dragOffset); //Solution might be here…

    } else if (indexPath.item == (self.currentFocusedItemIndex + 1) && indexPath.item != numberOfItems) {

        // The cell directly below the featured cell, which grows as the user scrolls
        CGFloat maxY = y + self.standardHeight;
        height =  self.standardHeight + MAX((self.focusedHeight - self.standardHeight) * self.nextItemPercentageOffset, 0);
        y = maxY - height;
       //attributes.transform = CGAffineTransformTranslate(attributes.transform, 0, -self.collectionView.contentOffset.y+self.dragOffset); 
    } else {
        y = frame.origin.y + frame.size.height;
       //attributes.transform = CGAffineTransformTranslate(attributes.transform, 0, -self.collectionView.contentOffset.y+self.dragOffset); 
    }

    frame = CGRectMake(0, y, self.collectionView.frame.size.width, height);
    attributes.frame = frame;

    [cache addObject:attributes];
    y = CGRectGetMaxY(frame);

    if (item == numberOfItems-1) {
        footerTop = CGRectGetMaxY(frame);
    }
};

for (NSUInteger item = 0; item < numberOfItems; item++) {
    if (item == 0) {
        footerTop = footerTop + self.focusedHeight;
    } else {
        footerTop = footerTop + self.standardHeight;
    }
}

CGSize footerSize = [self footerReferenceSizeInSection:0];
if (footerSize.height > 0) {
    UICollectionViewLayoutAttributes *footerAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter withIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
    footerAttributes.zIndex = 0;
    footerAttributes.frame = CGRectMake(0, footerTop, footerSize.width, footerSize.height);
    self.footerAttributes[0] = footerAttributes;
}
self.cachedLayoutAttributes = [cache copy];
}
Run Code Online (Sandbox Code Playgroud)

我已经更改了(https://github.com/fdzsergio/SFFocusViewLayout/tree/2.0.0)SFFocusLayout库的现有代码,这是我到目前为止所做更改的代码.为此,我提到了代码中的注释,我觉得解决方案存在但无法成功,因为我在过去3到4天都在努力.

请帮助我,并提前感谢.

使用gif文件所需的动画

Ket*_*n P 3

如果你想实现类似UltraVisualapp的动画。我修改了RPSlidingMenuprepareLayout中的方法。

prepareLayout以下是文件中方法中需要更改的内容RPSlidingMenuLayout.m

需要更改第一个单元格框架:

if (indexPath.row == topFeatureIndex) 
{
    // our top feature cell
    CGFloat yOffset = normalHeight  * topCellsInterpolation;
    yValue = self.collectionView.contentOffset.y - yOffset;
    CGFloat amountToGrow = MAX(featureHeight * topCellsInterpolation, 0);
    attributes.frame = CGRectMake(0.0f, self.collectionView.contentOffset.y -amountToGrow , screenWidth, featureHeight);
}
Run Code Online (Sandbox Code Playgroud)

对于第二个单元格但不适用于最后一个单元格:

else if (indexPath.row == (topFeatureIndex + 1) && indexPath.row != numItems)
{
        yValue = lastRect.origin.y + lastRect.size.height;
        CGFloat amountToGrow = MAX((featureHeight - normalHeight) *topCellsInterpolation, 0);
        CGFloat bottomYValue = yValue + normalHeight + amountToGrow;
        NSInteger newHeight = normalHeight + amountToGrow;
        attributes.frame = CGRectMake(0.0f, 0.0f , screenWidth, screenWidth);
}
Run Code Online (Sandbox Code Playgroud)

无需更改所有其他单元格框架。

您可以在随附的 gif 中看到动画。

动画可能看起来像你想要的!

希望它能帮助你...