我可以animation的UIScrollView contentOffset属性通过它的图层?
我想用CGPathRef来缩放和滚动一个UIScrollView。 正因为如此,我假设我必须animationUIScrollView的图层属性? 但是,我会animation哪些属性,使其相当于做一个UIViewanimation,并设置其contentOffset属性和zoomScale?
这些不是CALayer的属性。
任何想法,我将如何处理这个? 同样,只需要将scrollview移动到某个contentOffset和zoomScale,但不一定是线性的从A点到B点,A放大到B点。
我正在想一个CAKeyFrameAnimation与CGPathRef,但我不知道哪些属性animation。
你必须animationbounds
属性。 实际上,这就是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;
如果您好奇,我用来获取这些信息的方式如下:
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [scrollView setContentOffset:CGPointMake(200, 0) animated:NO]; [UIView commitAnimations]; NSLog(@"%@",scrollView);
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}>
animations
片段将列出所有活动的animation,在这种情况下{ bounds=<CABasicAnimation: 0xec1e7c0>; }
{ bounds=<CABasicAnimation: 0xec1e7c0>; }
。
希望这可以帮助。
移动一个CALayer是通过(最好是)设置它的.position属性来完成的 – 或者可能是anchorPoint(参考文档: http : //developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/ Introduction / Introduction.html )。
…但是我不认为如果你正在使用UIScrollView,你就不想搞CALayer。 你有没有尝试应用普通的CoreAnimations到你的ScrollView?
(问题是:UIScrollView是在CALayer之上实现的 – 所以即使你现在可以破解它,也很有可能在未来的iOS版本中被破解,如果可能的话,你想避免CALayer对于那个特定的类)