hor*_*oe7 24 core-animation uiscrollview cakeyframeanimation ios
我想使用CGPathRef缩放和滚动UIScrollView.因此我假设我必须为UIScrollView的图层属性设置动画?但是我会设置哪个属性动画会使它等同于执行UIView动画并设置其contentOffset属性和zoomScale?
这些不是CALayer的属性.
关于我如何处理这个问题的任何想法?同样,只想将滚动视图移动到某个contentOffset和zoomScale,但不一定是从A点到B点的线性移动,分别是缩放A到缩放B.
我正在考虑使用CGPathRef的CAKeyFrameAnimation,但我不知道要设置动画的属性.
pt2*_*ph8 54
你必须动画bounds财产.事实上,这就是该contentOffset物业在幕后使用的内容.
例:
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;
Run Code Online (Sandbox Code Playgroud)
如果您感到好奇,我以前获取此信息的方式如下:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[scrollView setContentOffset:CGPointMake(200, 0) animated:NO];
[UIView commitAnimations];
NSLog(@"%@",scrollView);
Run Code Online (Sandbox Code Playgroud)
的NSLog通话将输出:
<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}>
Run Code Online (Sandbox Code Playgroud)
该animations片段将列出所有活动的动画,在这种情况下{ bounds=<CABasicAnimation: 0xec1e7c0>; }.
希望这可以帮助.