У меня есть круговое изображение, которое вращается вокруг экрана, используя анимацию пути.И я хочу определить, когда пользователь касается движущегося круга.Однако даже если изображение вращается непрерывным кругом, его рамка все еще находится в верхнем левом углу, не двигаясь, как я могу обновить это, чтобы я мог обнаружить касание движущегося изображения?Вот код ...
Настройка анимации в ViewDidLoad:
//set up animation
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 10.0;
pathAnimation.repeatCount = 1000;
CGMutablePathRef curvedPath = CGPathCreateMutable();
//path as a circle
CGRect bounds = CGRectMake(60,170,200,200);
CGPathAddEllipseInRect(curvedPath, NULL, bounds);
//tell animation to use this path
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
//add subview
circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ball.png"]];
[testView addSubview:circleView];
//animate
[circleView.layer addAnimation:pathAnimation forKey:@"moveTheSquare"];
Метод касаний:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//detect touch
UITouch *theTouch = [touches anyObject];
//locate and assign touch location
CGPoint startPoint = [theTouch locationInView:self.view];
CGFloat x = startPoint.x;
CGFloat y = startPoint.y;
//create touch point
CGPoint touchPoint = CGPointMake(x, y);
//check to see if the touch is in the rect
if (CGRectContainsPoint(circleView.bounds, touchPoint)) {
NSLog(@"yes");
}
//check image view position
NSLog(@"frame x - %f, y - %f", circleView.frame.origin.x, circleView.frame.origin.y);
NSLog(@"center x - %f, y - %f", circleView.center.x, circleView.center.y);
NSLog(@"bounds x - %f, y - %f", circleView.bounds.origin.x, circleView.bounds.origin.y);
}
вид изображения, похоже, остается в левом верхнем углуручной угол.Кажется, я не могу понять, как распознать, был ли сделан жест касания на подвижном шаре.
любая помощь будет принята,
Крис