0

我有一個UICollectionView(iPad),它有一個jarry滾動。每個單元格都有一個白色的矩形UIView(帶有所有圓角),前面還有另一個UIImageView,只有頂部兩個角部被舍入。見下面這個鏈接此單元格的外觀 - i.stack.imgur.com/Ptlig.pngCAShapeLayer舍入角落影響性能

下面是該UICollectionViewCell

UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, (self.contentView.frame.size.width - 10), (self.contentView.frame.size.width - 10)*IMAGE_RATIO + 43.5)]; 
    bgView.backgroundColor = [UIColor clearColor]; 
    bgView.layer.cornerRadius = 10; 
    bgView.layer.borderWidth = 0.5f; 
    bgView.layer.borderColor = [UIColor colorWithRed: 179/255.0 green:181/255.0 blue:184/255.0 alpha:1.0].CGColor; 
    bgView.layer.backgroundColor = [UIColor whiteColor].CGColor; 
    bgView.layer.shouldRasterize = YES; 
    bgView.layer.rasterizationScale = [UIScreen mainScreen].scale; 
    [self.contentView addSubview:bgView]; 

    self.parablePost = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, (self.contentView.frame.size.width - 10), (self.contentView.frame.size.width-10)*IMAGE_RATIO)]; 
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.parablePost.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)]; 
    CAShapeLayer *maskLayer = [CAShapeLayer layer]; 
    maskLayer.frame = self.parablePost.bounds; 
    maskLayer.path = maskPath.CGPath; 
    self.parablePost.layer.mask = maskLayer; 
    [self.contentView addSubview:self.parablePost]; 

代碼當這條線「self.parablePost.layer.mask = maskLayer」的評論說,滾動順暢。所以CAShapeLayer會導致性能問題。我嘗試柵格化和手工繪製,而不是使用UIBezierPath,但它不能改善體驗。

有沒有更快的方法來回合UIImageView的兩個角落?

編輯:

我終於添加靜態圖像來模擬這給了我不滾動抖動相同的外觀中的UIImageView的頂部兩個角圓角。驚訝的是CAShapeLayer是一個性能流失。

+0

蒙版價格昂貴 - 它們是CPU渲染的。試着想想另一種方法來獲得你想要的外觀。 – nielsbot 2014-12-06 07:30:36

+0

也許更好的主意是使用普通的圓角圓角,但隱藏在單元格的白色信息部分後面的底部圓角。 – nielsbot 2014-12-09 02:23:08

+0

難道你不能只爲你的整個單元打開圓角,而不用擔心你的子層有圓角? – nielsbot 2014-12-09 02:23:57

回答

0

口罩很貴......(甚至可能用軟件渲染它們)。試着想想另一種方法來獲得你想要的外觀。例如,將圖像預渲染爲圖像...

+0

好評。由於這不是預渲染的靜態圖像,有沒有辦法按需預渲染圖像? – ADP 2014-12-06 07:34:32

+0

當然 - 你可以使用CGBitmapContext,但這可能不會更快。我問的是,你的單元格中的背景或部分可能是圖像(提前渲染或在軟件中渲染一次) – nielsbot 2014-12-09 02:21:12