Как вы можете определить касание изображения в Xcode? Я просмотрел документацию Apple, и это действительно сбивает с толку ... Я видел:
if (CGRectContainsPoint([imageView frame], location))
, но мое изображение по-прежнему не двигается. Я попытался использовать touchesBegan + touchesMoved и установил для userInteractionIsEnabled изображения значение YES, но он все равно не обнаружит его: (
EDIT: Большое спасибо за ваши замечательные предложения! В конце концов, я очень хотел чтобы сделать его как можно проще, и я знал, что мой код должен работать, поэтому я продолжал возиться с ним и после хорошего ночного сна понял, что это довольно простое решение:
In мои прикосновения Перемещено:
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
CGRect shapeRect = [imageView frame];
CGRect dropSquareRect = [dropSquare frame];
CGPoint touchLocation = CGPointMake(location.x, location.y);
if (CGRectContainsPoint(shapeRect, touchLocation))
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
[imageView setCenter:touchLocation];
[UIView commitAnimations];
}
if (CGRectIntersectsRect(shapeRect, dropSquareRect))
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.imageView.alpha = 0;
self.imageView.center = CGPointMake(dropSquare.center.x, dropSquare.center.y);
self.imageView.transform = CGAffineTransformMakeScale(0.8, 0.8);
[UIView commitAnimations];