我有一个UICollectionView,我在其中重复使用许多UICollectionViewCells的产品信息,想想Pinterest。

但是到了这个地步,我有了一个价格标签,并希望将每个单元的价格功能区旋转约45度。



实现此目标的最佳性能明智方法是什么?

我尝试过:

#import <QuartzCore/QuartzCore.h>

@interface ItemCollectionViewCell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UILabel *price;

@end


@implementation ItemCollectionViewCell

@synthesize price;

- (void)awakeFromNib {
    price.layer.transform = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);
    price.layer.transform = CATransform3DTranslate(price.transform, 25, -15, 0);
    price.layer.shouldRasterize = YES;
}

@end


但是,滚动和将新视图推入导航控制器的总体结果确实很慢。

更新资料


似乎iOS6自动布局是导致性能下降的主要原因,但我仍然不知道如何解决此问题或仅针对价格标签删除自动布局。

最佳答案

对我有用的是删除由UICollectionViewCell中的iOS6 autoLayout功能定义的属性,该属性在其中为price标签设置约束,它们是:

- (void)awakeFromNib {

    NSMutableArray* cons = [NSMutableArray array];
    //iterating through UICollectionViewCell constraint list
    for (NSLayoutConstraint* con in self.constraints) {
        //if the target constraint is `price` then add that to the array
        if (con.firstItem == price || con.secondItem == price) {
            [cons addObject:con];
        }
    }
    //remove the unwanted constraints array to the UICollectionViewCell
    [self removeConstraints:cons];

    //ready to roll…
    price.layer.transform = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);
    price.layer.transform = CATransform3DTranslate(price.transform, 25, -15, 0);
    price.layer.shouldRasterize = YES;
}

10-07 19:39
查看更多