다음은 간단한 예입니다. (프로젝트에 QuartzCore를 추가 한 후) : 간단하게하여 AddDelegate에 다음을 엑스 코드에서 새 프로젝트를 생성하고 입력하여 구현
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSView *thisView = [[NSView alloc] initWithFrame:CGRectInset([self.window.contentView bounds], 50, 50)];
[thisView setLayer:[CALayer layer]];
[thisView setWantsLayer:YES];
thisView.layer.delegate = self;
thisView.layer.backgroundColor = CGColorCreateGenericRGB(1,1,0,1);
thisView.layer.anchorPoint = NSMakePoint(0.5, 0.5);
[self.window.contentView addSubview:thisView];
//Create custom content
[thisView.layer display];
}
나는 또한 다음의 CALayer 대리자 메서드 구현 :
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
[[NSColor blueColor] setFill];
NSBezierPath *theBez = [NSBezierPath bezierPathWithOvalInRect:layer.bounds];
[theBez fill];
}
하는 경우를 이 코드를 실행하면 하위 뷰가 Windows contentView (큰 노란색 사각형)에 추가 된 것을 볼 수 있으며 레이어 호스팅 뷰라고 가정하고 ... 파란색으로 그려진 타원을 볼 수 있지만 아래에 노란색 직사각형이며 기본 창의 위치는 (0,0)입니다 ... 이것은 AC가 아닌 것 같습니다 노란색 레이어 내부에 그려져 있습니다.
내보기가 실제로 레이어 호스팅이 아니거나 레이어에 전달되는 컨텍스트가 잘못되었다고 추측하고 있습니다 ...하지만 왜 그 아래에 있을까요?
내가 뭔가 잘못하고 있어야합니다... 내가 지금처럼 레이어에 CABasicAnimation을 추가하는 경우
이, 이상한 것들로 계속하려면 :
CABasicAnimation *myAnimation = [CABasicAnimation animation];
myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
myAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
myAnimation.fromValue = [NSNumber numberWithFloat:0.0];
myAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
myAnimation.duration = 1.0;
myAnimation.repeatCount = HUGE_VALF;
[thisView.layer addAnimation:myAnimation forKey:@"testAnimation"];
thisView.layer.anchorPoint = NSMakePoint(0.5, 0.5);
이 노란색 배경이 애니메이션 도착 중심으로 회전, 그것의 중심이지만 파란색 타원은 레이어의 프레임 내부에서 올바르게 그려 지지만 (윈도우의 원점에서 바깥쪽에도 두 번 있기 때문에), 움직이지는 않습니다. 타원이 나머지 레이어와 함께 회전 할 것으로 기대합니다.
저는이 프로젝트를 기꺼이 해주는 사람들에게 available here을 만들었습니다.
르노