画像があり、ドラッグすると、左または右に触れるかどうかに応じて拡大します。たとえば、編集ソフトウェアのビデオ/オーディオ ハンドルなど。私の問題は、奇妙なことに、左側 (位置/サイズ システム) では機能しますが、右側では機能しません。右側では、ドラッグすると画像が指数関数的に拡大します。
これは私が使用するコードです:
- (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;
}
}
どうもありがとう!