ios - 考虑到性能,如何在 UICollectionViewCell 中旋转 UILabel?

标签 ios performance reusability uicollectionview uicollectionviewcell

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

但到了我有价格标签的地步,我想为每个单元格将价格带旋转大约 45 度。

please note the green price ribbon

实现该目标的最佳性能方法是什么?

我试过:

#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/

相关文章:

iphone - 在 UIView 上显示 XIB!如何设置?

iOS更改导航栏标题字体和颜色

javascript - jquery基础入门问题: How do i make my function reusable?

algorithm - Go 中的优先级队列实现

ios - 如何使用按钮处理 UITableViewCell 中的多点触控?

ios - 当用户扫描 Passbook 中我的密码时打开链接

ios - 对核心动画应用程序有什么优化方法建议吗?

python for循环和remove方法

Python beautifulsoup 解析速度提升

android - 在 Android 开发人员控制台上重复使用扩展文件