【问题标题】:UIImageView Handles drag systemUIImageView 处理拖动系统
【发布时间】:2012-05-25 12:09:12
【问题描述】:

我有一个图像,通过拖动,取决于我是触摸左侧还是右侧,它会展开。比如编辑软件视频/音频的句柄。 我的问题是,奇怪的是,它适用于左侧(使用位置/尺寸系统),但不适用于右侧。在右侧,当我拖动图像时,图像会呈指数级展开。

这是我使用的代码:

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

非常感谢!

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 当然,不要增加位置x,因为向右拉,框架必须保持停在左侧锚点上
    猜你喜欢
    • 2023-04-05
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多