到目前为止,我只看到 Core Animation 的代码看起来像这样,其中设置动画位置的参数是在开始时设置的。
- (void) startTopLeftImageViewAnimation{
/* Start from top left corner */
[self.xcodeImageView1 setFrame:CGRectMake(0.0f,0.0f, 100.0f, 100.0f)];
[self.xcodeImageView1 setAlpha:1.0f];
[UIView beginAnimations:@"xcodeImageView1Animation" context:(__bridge void *)self.xcodeImageView1];
/* 3 seconds animation */
[UIView setAnimationDuration:3.0f];
/* Receive animation delegates */ [UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(imageViewDidStop:finished:context:)];
/* End at the bottom right corner */ [self.xcodeImageView1 setFrame:CGRectMake(220.0f,
350.0f, 100.0f,
[self.xcodeImageView1 setAlpha:0.0f];
[UIView commitAnimations];
}
但是,我想制作一个图形跟随鼠标光标的动画。这意味着动画不断接收我的鼠标指针 xy 值。
有没有更好的选择来做这样的“手动”动画,并在我移动鼠标位置时调用 drawRect?我可以为此使用核心动画吗?
- (void)drawRect:(NSRect)rect
{
// Drawing code here.
[[NSColor whiteColor] set];
NSRectFill( rect );
[self drawCircleAtPoint:_circlePt];
}
- (void) drawCircleAtPoint:(CGPoint) point {
NSBezierPath* thePath = [NSBezierPath bezierPath];
NSRect nrect = NSMakeRect(point.x, point.y, 50, 50);
[thePath appendBezierPathWithOvalInRect:nrect];
[[NSColor blackColor] set];
[thePath stroke];
}
感谢您对此的任何帮助。