다음 스 니펫은 키 프레임 애니메이션을 사용하여 이라는보기를 회전합니다. 애니메이션은 첫 번째, 두 번째 및 마지막 프레임에서 각각 0º, 180º 및 360º로 회전 된보기로 1 초 이상 펼쳐진 3 프레임으로 구성됩니다. 코드는 다음과 같습니다.
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"];
특별한 것을 포함해야합니까? Xcode는 kCAMediaTimingFunctionLinear와 같은 모든 kCA에 대해 불평합니다. 그들은 알 수 없다. 당신이 뭔가가없는에 문제가있을 때마다 신분증 1 종료 상태 – Thanks
".objc_class_name_CAKeyframeAnimation"기호가 collect2 찾을 수 없습니다 발견되면 설명서에서 정의 된 위치를 검색해야합니다. 이 경우, 이러한 상수는 QuartzCore 프레임 워크의 일부인 CAMediaTiming & CAMediaTimingFunction에서 정의됩니다. QuartzCore.framework를 추가하지 않았다면 아마도 문제 일 것입니다. – Thanks
를 반환 문자 포인터 @__ OBJC @__ TestClass.o LD에서 CAKeyframeAnimation @ cls_refs :에서 참조 –