Как я могу осуществить определенное направление (т.е. по часовой стрелке) вращения в Базовой Анимации?

Хорошо, я был слепым:

e.which

будет содержать код ASCII ключа.

См. https://developer.mozilla.org/En/DOM/Event.which

9
задан Thanks 19 July 2009 в 10:46
поделиться

2 ответа

Следующий фрагмент кода поворачивает представление с именем someView , используя анимацию с ключевыми кадрами. Анимация состоит из 3 кадров, растянутых в течение 1 секунды, с поворотом обзора на 0º, 180º и 360º в первом, втором и последнем кадрах соответственно. Код следующий:

CALayer* layer = someView.layer;
CAKeyframeAnimation* animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];

animation.duration = 1.0;
animation.cumulative = YES;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

animation.values = [NSArray arrayWithObjects:
    [NSNumber numberWithFloat:0.0 * M_PI],
    [NSNumber numberWithFloat:0.5 * M_PI],
    [NSNumber numberWithFloat:1.0 * M_PI], nil];

animation.keyTimes = [NSArray arrayWithObjects:
    [NSNumber numberWithFloat:0.0],
    [NSNumber numberWithFloat:0.5],
    [NSNumber numberWithFloat:1.0], nil];

animation.timingFunctions = [NSArray arrayWithObjects:
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], nil];

[layer addAnimation:animation forKey:@"transform.rotation.z"];

Если вы используете анимацию против часовой стрелки, вы должны использовать отрицательные значения. Для немного более простой анимации вы можете использовать CABasicAnimation:

CALayer* layer = someView.layer;
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

animation.fromValue = [NSNumber numberWithFloat:0.0 * M_PI];
animation.toValue = [NSNumber numberWithFloat:1.0 * M_PI];

animation.duration = 1.0;
animation.cumulative = YES;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

[layer addAnimation:rotationAnimation forKey:@"transform.rotation.z"];
18
ответ дан 4 December 2019 в 11:07
поделиться

I believe you have to give it another "key frame" if you will to give Core Animation the hint that it needs to go that direction.

Make sure and turn off easing, (at least for the end/beginning of the middle step) otherwise the animation will not look smooth.

1
ответ дан 4 December 2019 в 11:07
поделиться
Другие вопросы по тегам:

Похожие вопросы: