UIImageView处理拖动系统

时间:2012-05-17 21:28:15

标签: objective-c xcode cocoa-touch uiimageview draggable

我有一个图像,通过拖动,取决于我是向左还是向右触摸,它会扩展。例如,编辑软件视频/音频处理。 我的问题是,奇怪的是,它适用于左侧(具有位置/大小系统),但不在右侧。在右侧,当我拖动图像时会以指数方式展开。

这是我使用的代码:

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

    UITouch *touch = [[event allTouches] anyObject];
    if ([touch view] == handlesImg) {

        UITouch *touch = [[event allTouches] anyObject];
        locationOne = [touch locationInView:touch.view];
       //Left
       if (locationOne.x < 12) {

            dragTimeLineInt = 1;

        }
       //Right
       else if (locationOne.x >  handlesImg.frame.size.width -12) {

        dragTimeLineInt = 2;


       }
    }
}

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

    [super touchesMoved:touches withEvent:event];

    CGPoint pt = [[touches anyObject] locationInView:handlesImg];
    CGRect frame = [handlesImg frame];

    float xSize = frame.size.width;
    float xPos = frame.origin.x;

    switch (dragTimeLineInt) {
        case 1: //Left

        xSize -= pt.x -locationOne.x;
        xPos += pt.x - locationOne.x;
        [handlesImg setFrame:CGRectMake(xPos, 0, xSize, 40)];

        break;

    case 2: //Right
        xSize += pt.x -locationOne.x;
        [handlesImg setFrame:CGRectMake(xPos, 0, xSize, 40)];

        break;

    default:
        break;
    }
}

非常感谢!

1 个答案:

答案 0 :(得分:0)

不确定这是否有帮助...但是在-touchesMoved:withEvent:方法中查看您的第二个案例陈述时,我注意到您没有像第一个案例陈述中那样更新xPos。这是故意的吗?

相关问题