0
我有一個圖像,並通過拖動,取決於如果我左或右觸摸它擴展。例如,編輯軟件視頻/音頻句柄。 奇怪的是,我的問題是它在左邊(有位置/大小系統),但不在右邊。在右側,當我拖動圖像以指數形式擴展時。UIImageView處理拖動系統
這是我使用的代碼:
- (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;
}
}
非常感謝!
當然,不要增加位置x,因爲拉到右邊,框架必須停留在左邊的定位點 – Vins
對不起@Vins,沒有更多的代碼去,我不禁:( – haroldcampbell