画像がXcodeでタッチされたかどうかをどのように検出できますか?画像がタッチされたかどうかを検出する方法
if (CGRectContainsPoint([imageView frame], location))
が、私のイメージはまだ動きません:私が見た ...私はアップル社のドキュメントを見ていると、それは本当に混乱しています。私はtouchesBegan + touchesMovedを使用してみました、とYESに画像のuserInteractionIsEnabledを設定するが、それはまだそれを検出しません:(
EDIT:!は最終的にはあなたの偉大な提案をとてもありがとうございました、私は実際にそれをできるだけシンプルにしたかった、と私は私のコードが仕事をする必要があることを知っていたので、私はそれをいじる保ち、良い夜の眠りの後、私はそれはかなり単純な解決策だった実現:
で私のtouchesMoved:
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];
これは、これは素晴らしいソリューションです...神 –