我有一个图像,通过拖动,取决于我是触摸左侧还是右侧,它会扩展。比如编辑软件视频/音频的句柄。我的问题是,奇怪的是,它适用于左侧(使用位置/尺寸系统),但不适用于右侧。在右侧,当我拖动图像时,图像会呈指数增长。
这是我使用的代码:
- (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;
}
}
多谢!