2009-11-15 2 views
5

아이폰의 좌표를 어떻게 변환하는지 알아보십시오.터치 좌표 (0-480 및 0-320 형식)

좌표를 얻으면 단 한번 터치하면됩니다.

나는 터치를 유지하고 그것을 풀어 놓으면 시작과 끝점의 차이를 보여줍니다.

터치의 절대 위치는 어떻게 얻습니까?

감사합니다.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 
    NSLog(@"X: %f",location.x); 
    NSLog(@"Y: %f",location.y); 
} 

I는 터치의 위치는 도면에 대해 계산

+0

당신은 당신의 코드 점점 좌표를 추가해야합니다 (오류를 줄 수도, 코딩 건조) – Francescu

답변

11

터치하여 드래그 (단 높이)을 리사이즈 할.

화면에 위치를 원하는 경우 수행 (? UIView의 서브 클래스)

UITouch * touch = [touches anyObject]; 
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow]; 
NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y); 

+0

당신을 감사합니다! 한면을 드래그하여 UIImageVIew의 크기를 조정하는 방법은 무엇입니까? – jacky

+0

UIImage 클래스를 사용한 적이 한번도 없습니다. UIImage 클래스를 참조하십시오. http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html. 더 구체적으로'drawInRect : – nash

+2

[touch locationInView : nil]이 동일한 결과를 제공하지 않습니까? 문서에서는 "터치 좌표를 창 좌표로 가져 오려면 아무 것도하지 않습니다."라고 말합니다. –