首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CALayer内UICollectionViewCell箍缩

CALayer内UICollectionViewCell箍缩
EN

Stack Overflow用户
提问于 2017-07-24 10:38:26
回答 2查看 319关注 0票数 3

我添加了一个GIF来描述一个问题。我有一个有很多单元格的UICollectionView,每个细胞里面都有一个CALayer。我在我的pinch中有一个UICollectionView手势。当它放大的时候,它看起来就像每个细胞被放大了一样。参见gif上单元格之间的空格。能把每个细胞放大吗?谢谢您的预告:

细胞亚类

代码语言:javascript
复制
@property (nonatomic, strong) CALayer *circularLayer;

- (void)layoutSubviews
{
    [self updateRoundedCorners];
}

- (void)updateRoundedCorners
{
    CGRect bounds = self.bounds;
    self.circularLayer.bounds = bounds;
    self.circularLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
}

#pragma mark - Property Set

- (void)setCellObject:(VenueLayoutCellObject *)cellObject
{
    self->_cellObject = cellObject;
    self.objectBackgroundColor = cellObject.objectColor;
    self.type = cellObject.type;
}

控制器

代码语言:javascript
复制
- (void)didReceivePinchGesture:(UIPinchGestureRecognizer *)gesture
{
    static CGFloat scaleStart;

    if (gesture.state == UIGestureRecognizerStateBegan) {
        scaleStart = self.venueLayoutZoom;
    }
    else if (gesture.state == UIGestureRecognizerStateChanged) {
        self.venueLayoutZoom = scaleStart * gesture.scale;
        [self.activeCollectionView.collectionViewLayout invalidateLayout];
    }
}

更新:

代码语言:javascript
复制
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    VenueLayoutCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kVenueLayoutCellReuseIdentifier forIndexPath:indexPath];
    self.activeCollectionViewCellsDictionary[indexPath] = cell;
    if (self.activeCollectionViewObjects.count > indexPath.section) {
        NSArray *rows = self.activeCollectionViewObjects[indexPath.section];
        if (rows.count > indexPath.row) {
            if ([rows[indexPath.row] isKindOfClass:[VenueLayoutCellObject class]]) {
                VenueLayoutCellObject *object = rows[indexPath.row];
                cell.cellObject = object;

            }
        }
    }
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    CGFloat widthAndHeight = [self widthAndHeightForActiveCollectionViewItem];
    return CGSizeMake(widthAndHeight *self.venueLayoutZoom, widthAndHeight * self.venueLayoutZoom);
}

- (CGFloat)widthAndHeightForActiveCollectionViewItem
{
    NSArray *array = self.activeCollectionViewObjects;
    __block NSInteger maxCount = 0;
    [array enumerateObjectsUsingBlock:^(NSArray *subArray, NSUInteger idx, BOOL * _Nonnull stop) {
        if (subArray.count > maxCount) {
            maxCount = subArray.count;
        }
    }];
    CGFloat widthAndHeight = CGRectGetWidth(self.activeCollectionView.bounds) / maxCount;
    return widthAndHeight;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-24 13:31:10

您对该层所做的更改是隐式动画,这意味着它们是用动画执行的,尽管您还没有具体告诉他们这样做。

因为您是在响应用户的手势,所以您不希望更改被动画化,因为这会使更改落后于手势。

可以在layoutSubviews期间关闭隐式动画,如下所示:

代码语言:javascript
复制
- (void)layoutSubviews
{
    [super layoutSubviews];
    [CATransaction begin];
    [CATransaction setDisableActions: YES];
    [self updateRoundedCorners];
    [CATransaction commit];
}
票数 1
EN

Stack Overflow用户

发布于 2017-07-24 12:46:17

细胞亚类

代码语言:javascript
复制
@property (nonatomic, strong) CALayer *circularLayer;

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self updateRoundedCorners];
}

我在这段代码中看到的唯一重要问题是缺少了超级layoutSubviews;如果它不能工作,请提供更多的代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45278399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档