2009-10-01 4 views
2

접촉 지점을 찾는 데 문제가 있습니다.목표 c/코코아 터치에서 접촉 지점 찾기

나는 16 타일 ()을 설정하는 loadView() 기능을 가지고 있습니다. 기능에서 다음

: 나는 어떤 프레임/타일을 식별하기 위해 프레임을 사용했다

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event 
{ 
    // Retrieve the touch point 

    UITouch *touch=[[event allTouches]anyObject]; 
    CGPoint point= [touch locationInView:touch.view]; 
    CGRect frame = [self frame]; // Error this Line 
} 

는 프레임 기원을 사용하여 누를 때.

그러나이 라인 :

CGRect frame = [self frame]; 

은 나를 미치게 만든다. Plz 누군가 나에게 무엇을해야하는지 말해. (설명과 왜 일하지 않는지). Plz.

+1

어떤 종류의 오류가 발생했는지 알려주시겠습니까? 또한이 메소드가 어떤 클래스에 있는지 알려주십시오. – newacct

+0

예, 문제를 해결할 수 있도록 더 자세한 정보를 제공해야합니다. –

답변

2

UIViewController 하위 클래스의 메서드에서이 작업을 수행하려는 것 같습니다. 난 아직도 당신이 원하는에 조금 불분명 오전

UITouch *touch=[[event allTouches]anyObject]; 
CGPoint point= [touch locationInView:self.view]; 
4

사용이 : 라인은 아마이어야한다.

다른 개체를 이동하는 경우 다른 클래스를 만들고 UIView에서 상속하고 자식 클래스에서 터치 함수를 정의하는 것이 어떻습니까?

... 
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint touchPoint = [touch locationInView:[self superview]]; 

} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint touchPoint = [touch locationInView:[self superview]]; 
    self.center = touchPoint; 
} 
... 

그렇지 않으면 단지의 UIViewController에서 터치 포인트를 원하는 경우 예 헤더

... 
Tile : UIView 
... 

예 클래스의 구현입니다.

UITouch *touch = [touches anyObject]; 
CGPoint touchPoint = [touch locationInView:[self.view]]; 
0

, 그러나 이것은 당신을 도움이되는지 보자 :

[self.view frame];