2

我在将新创建的视图放置在 UICollectionView 单元格上时遇到问题(并将其增长以填充屏幕)。当集合视图滚动到顶部时效果很好,但是一旦滚动,我就无法正确放置新视图,因为我收集的浮点值低于窗口高度。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    UIView *picturesView = [[UIView alloc] init];
    picturesView.frame = CGRectMake(CGRectGetMidX([[collectionView cellForItemAtIndexPath:indexPath] bounds]), CGRectGetMidY([[collectionView cellForItemAtIndexPath:indexPath] bounds]), 100, 100);

    [self.view addSubview:picturesView];

    [UIView animateWithDuration:0.3 animations:^{
        picturesView.frame = CGRectMake(0, 0, windowWidth, windowHeight);
        picturesView.alpha = 1.0;
    }];
}

这里的问题是 CGRectMake 的 x 和 y 参数中的值大于滚动后的可用窗口区域,并且视图出现在滚动剪辑下方(新创建的视图似乎从屏幕底部向上滑动,这不是所需的动画)。

逻辑会让我通过 positionY = ((totalScrollHeight - topScrollAreaClipped) + screenPositionOfCell) 计算这些应该放在哪里。我似乎无法获得的唯一变量是被滚动剪辑的 UICollectionView 的高度。

除非有更好的方法来做到这一点。

4

1 回答 1

0

您需要补偿UICollectionView. 检查scrollOffsett属性,并从您的 x/y 位置减去该值,为您的UIView.

于 2013-01-26T07:37:26.837 回答