Ho avuto un problema simile ruotando attorno all'asse z. Setting shouldRasterize = YES ha prevenuto i bordi frastagliati comunque a un costo di prestazioni. Nel mio caso stavo riutilizzando le viste (e i suoi livelli) e mantenendo il dovrebbe shouldRasterize = YES stava rallentando le cose.
La soluzione era quella di disattivare la rasterizzazione subito dopo che non ne avevo più bisogno. Tuttavia, poiché l'animazione gira su un altro thread, non c'era modo di sapere quando l'animazione era completa ... fino a quando ho scoperto un metodo CATransaction estremamente utile. Si tratta di un codice che ho usato e dovrebbe illustrare il suo uso:
// Create a key frame animation
CAKeyframeAnimation *wiggle = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
NSInteger frequency = 5; // Higher value for faster vibration
NSInteger amplitude = 25; // Higher value for lower amplitude
// Create the values it will pass through
NSMutableArray *valuesArray = [[NSMutableArray alloc] init];
NSInteger direction = 1;
[valuesArray addObject:@0.0];
for (NSInteger i = frequency; i > 0; i--, direction *= -1) {
[valuesArray addObject:@((direction * M_PI_4 * (CGFloat)i/(CGFloat)amplitude))];
}
[valuesArray addObject:@0.0];
[wiggle setValues:valuesArray];
// Set the duration
[wiggle setAdditive:YES];
[wiggle setValueFunction:[CAValueFunction functionWithName:kCAValueFunctionRotateZ]];
[wiggle setDuration:0.6];
// Turn on rasterization to prevent jagged edges (anti-aliasing issues)
viewToRotate.layer.shouldRasterize = YES;
// ************ Important step **************
// Very usefull method. Block returns after ALL animations have completed.
[CATransaction setCompletionBlock:^{
viewToRotate.layer.shouldRasterize = NO;
}];
// Animate the layer
[viewToRotate.layer addAnimation:wiggle forKey:@"wiggleAnimation"];
funzionato come un fascino per me.
Non ho provato a utilizzare questo con animazioni implicite (ad esempio le animazioni che si verificano a causa della modifica del valore nella proprietà animabile per un livello non associato alla vista), tuttavia mi aspetto che funzioni finché il metodo CATransaction viene chiamato prima la modifica della proprietà, come garanzia che il blocco viene assegnato a CATransaction prima che inizi un'animazione.
È possibile aggiungere 'view.layer.rasterizationScale = [[UIScreen mainScreen] scala];' per evitare sfocature sugli schermi Retina. –
Questo commento dovrebbe far parte della risposta. L'impostazione della proprietà 'shouldRasterize' non è sufficiente! –
Hai ragione. Fatto. – tarmes