у меня есть круговое изображение, которое вращается вокруг экрана, используя анимацию пути. И я хочу определить, когда пользователь касается движущегося круга. Однако, хотя изображение движется по непрерывному кругу, его рамка все еще находится в верхнем левом углу и не движется, как я могу обновить это, чтобы я мог обнаружить прикосновение к движущемуся изображению? Вот код...
Настройте анимацию в 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);
}
изображение, кажется, остается в верхнем левом углу. Кажется, я не могу понять, как распознать, был ли сделан сенсорный жест на движущемся шаре.
любая помощь будет оценена по достоинству,
Крис