ios uiscrollview core-animation cakeyframeanimation

ios - ¿Puedo animar la propiedad UIScrollView contentOffset a través de su capa?



core-animation cakeyframeanimation (2)

Mover un CALayer alrededor se realiza (preferiblemente) configurando su propiedad .position - o posiblemente el anchorPoint (consulte los documentos en: http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html ).

... pero no creo que quieras meterte con CALayer si estás trabajando con un UIScrollView. ¿Ha intentado aplicar CoreAnimations simples a su ScrollView?

(El problema es: el UIScrollView se implementa en la parte superior de CALayer, por lo que incluso si puede hacerlo funcionar en la actualidad, es muy probable que se rompa en las futuras versiones de iOS.

Quiero hacer zoom y desplazar un UIScrollView con un CGPathRef. ¿Por eso asumo que tengo que animar la propiedad de capa de UIScrollView? Pero, ¿qué propiedad animaría que lo haría equivalente a hacer una animación UIView y establecer su propiedad contentOffset y zoomScale?

Estas no son propiedades de un CALayer.

¿Alguna idea de cómo abordaría esto? Nuevamente, solo desea mover la vista de desplazamiento a un cierto ContentOffset y zoomScale, pero no necesariamente de forma lineal desde el punto A al punto B, el zoom A al zoom B, respectivamente.

Estaba pensando en un CAKeyFrameAnimation con un CGPathRef, pero no sé qué propiedades animar.


Tienes que animar la propiedad de los bounds . De hecho, eso es lo que la propiedad contentOffset usa detrás de escena.

Ejemplo:

CGRect bounds = scrollView.bounds; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"]; animation.duration = 1.0; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.fromValue = [NSValue valueWithCGRect:bounds]; bounds.origin.x += 200; animation.toValue = [NSValue valueWithCGRect:bounds]; [scrollView.layer addAnimation:animation forKey:@"bounds"]; scrollView.bounds = bounds;

Si tienes curiosidad, la forma en que solía obtener esta información es la siguiente:

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [scrollView setContentOffset:CGPointMake(200, 0) animated:NO]; [UIView commitAnimations]; NSLog(@"%@",scrollView);

La llamada NSLog dará salida:

<UIScrollView: 0x860ba20; frame = (-65.5 0; 451 367); clipsToBounds = YES; autoresize = W+RM+TM+H; animations = { bounds=<CABasicAnimation: 0xec1e7c0>; }; layer = <CALayer: 0x860bbc0>; contentOffset: {246, 0}>

El fragmento de animations mostrará una lista de todas las animaciones activas, en este caso { bounds=<CABasicAnimation: 0xec1e7c0>; } { bounds=<CABasicAnimation: 0xec1e7c0>; } .

Espero que esto ayude.