タッチの場所を記録しようとしています。以下は私のコードです。私が理解している限り、iPadを縦向きに持っていると仮定すると、左上隅に触れると(0,0)の位置が得られ、右下隅は(768, 1024)になります。 . ただし、左上隅の (-6, -18) と右下隅の (761,1003) のような値を取得しています。どうやら座標がずれたようです。self.bounds をトレースすると、{{0,0}, {768, 1024}} が得られます。誰かが私にこれを説明できますか?境界 {{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));
}