UIImageView があり、ユーザーが画像をタップしたかどうかを知りたい場合。touchesBegan では、次のことを行いますが、常に最初の条件で終了します。ウィンドウは縦向きモードで、画像は下部にあります。ウィンドウの右上をタップしても最初の状態に入ることができますが、これは非常に正しくないようです。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(myimage.frame, location) == 0){
//always end up here
}
else
{ //user didn't tap inside image}
値は次のとおりです。
location: x=303,y=102
frame: origin=(x=210,y=394) size=(width=90, height=15)
助言がありますか?