Ios UITextView拖放操作有问题

Ios UITextView拖放操作有问题,ios,objective-c,uitextview,Ios,Objective C,Uitextview,我正试图用触摸拖动UITextView对象!但我有一个问题,我需要当用户触摸自定义视图时,触摸事件开始,但触摸方法仅对self.view有效。这是我的密码: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touch began "); UITouch *touch = [touches anyObject]; startingX = [touch location

我正试图用触摸拖动
UITextView
对象!但我有一个问题,我需要当用户触摸
自定义视图时,触摸事件开始,但触摸方法仅对
self.view
有效。这是我的密码:

- (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;
}

我的文本视图不可编辑所有视图都是
userInteractionEnabled

在自定义文本视图中编写
触动开始
方法和
触动移动
方法,并尝试调整框架。

触动开始,触动移动方法在UIView子类化时被调用。您必须将View@SunnyShah对不起,我不明白?自定义视图只是一个UIView而不是ViewController!