Я написал анимацию для слоя, который перемещает слой из одной позиции в другую:
- (void) animateCentreRightTransition: (int) transition {
float scaleFactor[2] = {1, 0.8};
if (transition == WatchTransitionClockwisePortrait || transition == WatchTransitionClockwiseLandscape) {
scaleFactor[0] = 0.8;
scaleFactor[1] = 1;
}
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, kCentreRightTrasition[transition][0], kCentreRightTrasition[transition][1]);
CGPathAddCurveToPoint(curvedPath, NULL, kCentreRightTrasition[transition][2], kCentreRightTrasition[transition][3], kCentreRightTrasition[transition][4], kCentreRightTrasition[transition][5], kCentreRightTrasition[transition][6], kCentreRightTrasition[transition][7]);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath: @"transform.scale"];
scale.fromValue = [NSNumber numberWithDouble:scaleFactor[0]];
scale.toValue = [NSNumber numberWithDouble:scaleFactor[1]];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:scale, pathAnimation, nil];
group.autoreverses = NO;
group.duration = kWatchTransitionDuration;
group.repeatCount = 1;
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
group.delegate = self;
[self.layer addAnimation:group forKey:@"animateCentreRightTransition"];
NSLog(@"Centre right %f", self.layer.position.x);
NSLog(@"%f", self.layer.position.y);
}
Но что, по-видимому, заключается в том, что, пока мой слой перемещается на новое место, его свойство позиции остается прежним?Теперь, когда я поворачиваю экран и устанавливаю координаты положения, чтобы соответствовать ландшафтному режиму, результат не тот, который я хочу, слой не остается там, где я хочу.Что мне здесь не хватает?