我有一个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
但是滚动并将新视图推入导航控制器的整体结果非常慢。
答案 0 :(得分:3)
对我来说有用的是删除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;
}