タッチの位置を記録しようとしています。以下は私のコードです。私が理解する限り、非常に遠い左上隅のタッチは私に(0,0)の位置を与え、非常に遠い右下の角は(768、1024)私が肖像画。しかし、左上隅には(-6、-18)、右下には(761,1003)のような値が得られます。座標が何とかシフトされているように見えます。 {{0,0}、{768、1024}}のself.boundsのトレースがあります。誰かが私にこれを説明することはできますか?私は境界{{0,0}、{768、1024}}の間にあるxとyの値を取得したいと思います。事前にどうもありがとうございました。タッチ位置の値がビューの境界から外れる
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
NSLog(@"frame: %@", NSStringFromCGRect(bounds)); // this value was traced as frame: {{0, 0}, {768, 1024}}
UITouch* touch = [[event touchesForView:self] anyObject];
location = [touch locationInView:self];
NSLog(@"Location: %@", NSStringFromCGPoint(location));
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] anyObject];
location = [touch locationInView:self];
NSLog(@"Location: %@", NSStringFromCGPoint(location));
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch* touch = [[event touchesForView:self] anyObject];
location = [touch locationInView:self];
NSLog(@"Location: %@", NSStringFromCGPoint(location));
}
これらの接触は、ビューがメインウィンドウ上でオフセットされているビューコントローラで起こっていますか? – rooster117
これらのタッチメソッドは、UIViewのサブクラスに実装されています。このビューは、ビューコントローラに追加されました。このビューには、x = 0、y = 0、width = 768、height = 1024(サイズインスペクタから)があります。 – HappyAppDeveloper
私の推測では、あなたのインターフェースのビルドが、間違って整列されたビューまたはそれに類するもののように、何とかうんざりしていることでしょう。完全に新しいプロジェクトを作成し、そこで動作するかどうかを確認してください。 – jimpic