2014-04-17 5 views
0

나는 터치로 UITextView 개체를 드래그하려고합니다! 하지만 문제가있어 사용자가 custom view을 터치 할 때 터치 이벤트가 시작되지만 터치하는 방법은 self.view에서만 작동해야합니다. 여기 내 코드는 다음과 같습니다UITextView에서 드래그 앤 드롭으로 문제가 발생했습니다.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"touch began "); 

    UITouch *touch = [touches anyObject]; 

    startingX = [touch locationInView:_captureView].x; 
    startingY = [touch locationInView:_captureView].y; 
} 




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



    CGPoint currentPoint = _mText.frame.origin; 

    float xForView, yForView; 
    UITouch *touch = [touches anyObject]; 
    float newX = [touch locationInView:_captureView].x; 
    float deltaX; 


    if(startingX > newX){ 
     deltaX = startingX - newX; 
     xForView = currentPoint.x - deltaX; 
    } else if(newX > startingX){ 
     deltaX = newX - startingX; 
     xForView = currentPoint.x + deltaX; 
    } else xForView = currentPoint.x; 


    float newY = [touch locationInView:_captureView].y; 
    float deltaY; 

    if(startingY > newY){ 
     deltaY = startingY - newY; 
     yForView = currentPoint.y - deltaY; 
    } else if(newY > startingY){ 
     deltaY = newY - startingY; 
     yForView = currentPoint.y + deltaY; 
    } else yForView = currentPoint.y; 



    CGRect newFrame = CGRectMake(xForView, yForView, _mText.frame.size.width, _mText.frame.size.height); 
    _mText.frame = newFrame; 

    startingX = newX; 
    startingY = newY; 
} 

내 텍스트 뷰는 모든 뷰가 touches began 방법과 사용자 지정 텍스트보기 내부 touches moved 방법을 쓰기 프레임을 조정하려고 userInteractionEnabled

+0

touchesBegan, touchesMoved 메서드는 UIView를 서브 클래스로 호출 할 때 호출됩니다. 당신은 서브 클래 싱해야합니다 –

+0

@SunnyShah 미안해! ? –

답변

0

입니다하지 편집입니다.

+0

사용자 정의보기는 ViewController가 아닌 UIView입니다! –

관련 문제