6

UIScrollView で zoomScale を 1 に戻す必要がありますが、アニメーション化する必要があります。これにはCABasicAnimationが使えると思ったのですが、NSValueには「valueForFloat」や「valueForNSNumber」がないようで、CABasicAnimationのanimation.fromValueやanimation.toValueに何を使えばいいのかわかりません。これについてもっと良い方法はありますか?

編集:これを機能させるには何を追加する必要がありますか?

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"zoomScale"];
        animation.duration = 2.3;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];        
        animation.fromValue = [NSNumber numberWithFloat:myScrollview.zoomScale];
        animation.toValue = [NSNumber numberWithFloat:1.0];

        [myScrollview.layer addAnimation:animation forKey:@"zoomScale"];
4

1 に答える 1

14

CAAnimationこの単純なことに頼る必要はありません。2 番目のパラメーターとして-[UIScrollView setZoomScale:animated:]pass を使用するだけです。YES

いずれにせよ、アニメーションの一部を変更したい場合は、代わりに「UIView アニメーション」を使用できzoomScaleますCAAnimation

次のようなことを試しましたか?

[UIView animateWithDuration:2.0
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{ [myScrollView setZoomScale:1.0f animated:NO]; }
                 completion:nil];
于 2013-06-11T21:06:29.880 に答える