2012-12-14 4 views
1

UIView 서브 클래 싱이 처음에는 내보기가 기본 색으로되어 있고 여기에 문제가있는 x 축 = 0에서 사용자가 접촉 한 지점에서 다른 색으로 채울 필요가 있습니다. touchesMoved입니다. 내 자체 뷰 경계 밖으로 드래그해도 그 점을 얻고 있습니다. 내 자체 뷰 경계에서만이를 제한하는 방법입니다. touchesMoved 내 뷰 경계 밖으로 도달

나는

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    { 
     UITouch *touch = [touches anyObject]; 
     CGPoint point = [touch locationInView:self]; 
     endPoint = point; 
     NSLog(@"moved x: %f,y: %f",point.x,point.y); 
     if(CGRectContainsPoint([self frame], endPoint)){ // this also not working 
      [self fillColor]; 
     } 
    } 

어떤 도움 사전에 감사합니다, &은 다음과 같습니다 조각 아래에 있지만 방법을있는 touchesMoved 내 행운

if([self pointInside:point withEvent:nil]){ 
    [self fillColor]; 
} 

의 노력 봤.

답변

0

touchesMoved 메서드에서 CGPoint point = [touch locationInView:self]; replcae self를 터치하여 원하는 부분을 터치합니다.

자체는 전체보기를 가져오고, 거기에 그리기보기를 전달해야합니다. 그러면 해당보기에서만 터치가 감지됩니다.

0

그냥 ...

fillColorView.tag = 111; 

와 울부 짖는 소리와 같은 touchesMoved: 방법에 울부 짖는 소리 논리를 사용 ..

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *tap = [touches anyObject]; 
    CGPoint pointToMove = [tap locationInView:fillColorView]; 
    if([tap.view isKindOfClass:[UIView class]]) 
    { 
     UIView *tempView=(UIView *) tap.view; 
     if (tempView.tag == 111){ 
       [self fillColor]; 
     } 
    } 
} 

희망이 도움이 당신에게 .. 태그 viewDidLoad: 방법과 울부 짖는 논리를 사용 설정

+0

것은 위의 코드 스 니펫은 내보기 클래스 (fillColorView)에 &이보기를 만들고있어 [anyParentViewController addSubView : fillColorView] 그래서 내가 이것을 사용할 때 anyParentV 필자는 필자가 fillColorView에서 손가락을 드래그하더라도 내 anyParentViewController에서 채우기 색상 인 fillColorView로 손가락을 드래그하더라도 UI가 실행 중입니다. –

+0

CGPoint pointToMove = [탭 위치 정보보기 : fillColorView]; 또한 내 벨로우즈 코드 친구를 사용하십시오 또한 사용보기에서 선을 그릴 수있는 iPad이 응용 프로그램 의이 유형을 만들 –

+0

fillColorView 친구를위한 @GrahamBell 세트 태그도 업데이트 된 대답을 참조하십시오 .. –