Мое приложение имеет UITableView и ячейки, которые содержат несколько UIImageViews, эти изображения имеют слой shadow и cornerRadius. Для того, чтобы повысить производительность, я используюМое приложение использует много памяти, когда я использую imageView.layer.shouldRasterize = YES
//if set to NO, tableView is slow to move
imageView.layer.shouldRasterize = YES;
//solve image become blurry problem
imageView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
Но когда я загружаю много клеток, он использует много памяти и аварий с этой ошибкой:
CGBitmapContextInfoCreate: unable to allocate 283136 bytes for bitmap data
Как я могу это исправить?
Edit 1
В CAlayer.h
/* When true, the layer is rendered as a bitmap in its local coordinate
* space ("rasterized"), then the bitmap is composited into the
* destination (with the minificationFilter and magnificationFilter
* properties of the layer applied if the bitmap needs scaling).
* Rasterization occurs after the layer's filters and shadow effects
* are applied, but before the opacity modulation. As an implementation
* detail the rendering engine may attempt to cache and reuse the
* bitmap from one frame to the next. (Whether it does or not will have
* no affect on the rendered output.)
*
* When false the layer is composited directly into the destination
* whenever possible (however, certain features of the compositing
* model may force rasterization, e.g. adding filters).
*
* Defaults to NO. Animatable. */
@property BOOL shouldRasterize;
'попытка кэшировать'
Я думаю, что это загрузить изображения и эти данные теневые памяти и вызвать его использует много памяти.
Performance scrolling and retina resolution images in CALayer
Drawing mask influence performance
полный код:
imageView.layer.borderWidth = 0.2;
imageView.layer.borderColor = [UIColor colorWithWhite:0.95 alpha:1].CGColor;
imageView.layer.cornerRadius = 2;
imageView.layer.shouldRasterize = YES;
imageView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
UIView *shadowView = [[UIView alloc] init];
shadowView.backgroundColor = [UIColor whiteColor];
//set layer, if I don't use shadow view
shadowView.layer.shadowColor = [UIColor colorWithWhite:0.93 alpha:1].CGColor;
shadowView.layer.cornerRadius = 2;
shadowView.layer.shadowOffset = CGSizeMake(1,1);
shadowView.layer.shadowOpacity = 1;
shadowView.layer.shadowRadius = 0.6;
shadowView.layer.shouldRasterize = YES;
shadowView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
[shadowView setFrame:containerFrame];
[shadowView addSubview:imageView];
//add shadowView to cell ...
А? _Как я могу владеть рыбой и лапой медведя? _ – Avi
@Avi, он имеет в виду, как он может получить оба. Прокрутка в режиме просмотра стола идеально подходит для решения этой проблемы. Собственная рыба и медвежья лапа (Mencius idiom) – gurmandeep
Я до сих пор никогда не слышал эту идиому. Возможно, это не лучший способ сформулировать вопрос SO. – Avi