Objective c UIImageView控制柄拖动系统

Objective c UIImageView控制柄拖动系统,objective-c,xcode,cocoa-touch,uiimageview,draggable,Objective C,Xcode,Cocoa Touch,Uiimageview,Draggable,我有一个图像,通过拖动,取决于我是向左还是向右触摸,它会展开。例如,编辑软件视频/音频句柄。 奇怪的是,我的问题是,它在左侧工作(使用位置/大小系统),但在右侧不工作。在右侧,当我拖动图像时,图像将以指数方式展开 这是我使用的代码: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; if ([tou

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

这是我使用的代码:

- (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;
    }
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[[event AllTouchs]anyObject];
如果([touch view]==handlesImg){
UITouch*touch=[[event AllTouchs]anyObject];
locationOne=[touch locationInView:touch.view];
//左
如果(位置1.x<12){
dragTimeLineInt=1;
}
//对
else if(locationOne.x>handlesImg.frame.size.width-12){
dragTimeLineInt=2;
}
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
[超级触摸移动:触摸事件:事件];
CGPoint pt=[[touchs anyObject]locationInView:handlesImg];
CGRect帧=[handlesImg帧];
float xSize=frame.size.width;
float xPos=frame.origin.x;
开关(dragTimeLineInt){
案例1://左
xSize-=pt.x-locationOne.x;
xPos+=pt.x-locationOne.x;
[handlesImg setFrame:CGRectMake(xPos,0,xSize,40)];
打破
案例2://对
xSize+=pt.x-locationOne.x;
[handlesImg setFrame:CGRectMake(xPos,0,xSize,40)];
打破
违约:
打破
}
}

非常感谢

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

当然,不要增加位置x,因为向右拉动时,机架必须保持在左锚定点停止