我有一个 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
但滚动新 View 并将新 View 推送到导航 Controller 的总体结果确实很慢。
更新
- 看来 iOS6 Autolayout 是导致性能下降的主要原因,但我仍然不知道如何解决这个问题或仅针对价格标签删除 autolayout。
最佳答案
对我有用的是删除 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;
}
关于ios - 考虑到性能,如何在 UICollectionViewCell 中旋转 UILabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14274784/