我有一个图像,通过拖动,根据我触摸左侧或右侧,它会扩展。例如编辑软件视频/音频句柄。我的问题是,奇怪的是,它在左边有效(使用位置/大小系统),但在右边不起作用。在右边,当我拖动图像时,图像会呈指数级扩展。
这是我使用的代码:
- (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;
}
}非常感谢!
发布于 2012-05-18 06:21:12
不确定这是否有帮助...但是查看-touchesMoved:withEvent:方法中的第二个case语句,我注意到您没有像在第一个case语句中那样更新xPos。这是故意的吗?
https://stackoverflow.com/questions/10643793
复制相似问题