我拿了一個UIView application.i置於控制器的view.my需求的圖像使用鼠標的形象應該是可移動的mouse.mouse的幫助下應該選擇圖像和圖像移動應該在拖動鼠標時移動。圖像移動應該僅限於視圖的特定部分。 有人可以幫我提前圖像應在某一特定領域
dinakar
我拿了一個UIView application.i置於控制器的view.my需求的圖像使用鼠標的形象應該是可移動的mouse.mouse的幫助下應該選擇圖像和圖像移動應該在拖動鼠標時移動。圖像移動應該僅限於視圖的特定部分。 有人可以幫我提前圖像應在某一特定領域
dinakar
這可以用的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) ;
}
希望這應該是有幫助的。
Dinakar代碼的理想任務 TNX我很遺憾地告訴你,沒有鼠標(光標)在iPhone或iPad。
你需要做的是在那個地方創建一個UIScrollView,而不是在.m文件中定義它的大小(UIScrollView)並且休息將被照顧 – Robin 2011-01-11 05:55:56
沒有鼠標指針事件,確切地說! – Mahesh 2011-01-11 06:53:52