2011-01-11 9 views
2

私はuiview application.iを取ったコントローラのview.my要件に画像を置いた画像はマウスの助けを借りて移動可能でなければなりません。マウスをドラッグすると移動する必要があります。画像の移動は、ビューの特定の部分のみに制限する必要があります。 は、誰かが私は、マウス(カーソル)はiPhoneやiPadには存在しないことを伝えることは非常に残念ですdinakar画像は特定の領域でマウスを使用して移動する必要があります

答えて

2

これは、touchesBeganイベントとtouchesMovedイベントで実行できます。

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    // This gets you starting position of 
    UITouch *touch = [ [ event allTouches ] anyObject ] ; 

    float touchXBeginPoint = [ touch locationInView:touch.view ].x ; 
    float touchYBeginPoint = [ touch locationInView:touch.view ].y ; 

    // Calculate the offset between the current image center and the touched points. 
    // Moving image only along X - direction and try thinking as how to move in 
    // any direction using this as a reference. It isn't that hard. 

    touchOffset = image.center.x - touchXBeginPoint ; 
    // touchOffset should be a member variable of class or a variable with global scope 

} 

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    // Calculate the difference from previous position and the current position 
    // Add this difference to the previous point and move the image center to that point. 
    // How ever, you should have an UIImageView outlet connected on to the image placed 
    // on the interface builder. 

    // And regarding image movement restriction, since you always have co-ordinates with 
    // you, you can set the boundaries. 

    UITouch *touch = [ [ event allTouches ] anyObject ] ; 

    float distanceMoved =([ touch locationInView:touch.view ].x + touchOffset) - image.center.x ; 
    float newX = image.center.x + distanceMoved ; 

    if(newX > 30 && newX < 290) // setting the boundaries 
     image.center = CGPointMake(newX, image.center.y) ; 
} 

希望します。

+0

hii mahesh tnxのanswer.theアプローチは、このコードで試したものと同じです:[scale setFrame:CGRectMake(touchXBeginPoint +(touchLocation-touchXBeginPoint)、touchYBeginPoint +(touchLocation-touchYBeginPoint)、scaleFrame.size.width、scaleFrame。 size.height)];スケールは私が取得したimageView.theエラーです。 'touchXBeginPoint' undeclared.can uplsはthis.ifを見て、私のコードを理解できませんでした。plzは私のtask.iに応じてサンプルコードを与えてくれました。あなたが私を助けることを望みます。 – Dinakar

+0

'エラーは 'touchXBeginPoint' undeclared'です - エラーメッセージははるかに明確です。どのように、新しいコードを投稿しました。 Ishuのリンクを参照してください。 – Mahesh

3

Dinakar

事前に私が望ましいタスク TNXをコーディングすることができます。

+1

あなたがする必要があるのは、その場所に画像を作成し、.mファイルよりサイズを定義して(UIScrollView)、残りの部分を処理することです。 – Robin

+0

マウスポインタのイベントはありません。 – Mahesh

+0

いいえデバイスにマウスポインタがありません。デバイスがタッチセンシティブである場合、マウスが必要なのはなぜですか? – Robin

3

ロビンは、これらのは、あなたがこのlink images.see移動するためのチュートリアルを読む必要があり、別のイベント

ではありませんので、ちょうどシミュレータ用のタッチとして使用right.mouseカーソルです。

これはあなたに役立つでしょう。

関連する問題