首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIImageView手柄拖动系统

UIImageView手柄拖动系统
EN

Stack Overflow用户
提问于 2012-05-18 05:28:15
回答 1查看 124关注 0票数 0

我有一个图像,通过拖动,根据我触摸左侧或右侧,它会扩展。例如编辑软件视频/音频句柄。我的问题是,奇怪的是,它在左边有效(使用位置/大小系统),但在右边不起作用。在右边,当我拖动图像时,图像会呈指数级扩展。

这是我使用的代码:

代码语言:javascript
复制
- (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;
    }
}

非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2012-05-18 06:21:12

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10643793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档