2010-05-08 97 views
0

我喜歡水平拖動該對象,而不是垂直的,這是目前杜安它:拖動對象垂直

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 
    if (CGRectContainsPoint(myObject.frame, location)){ 
    CGPoint xLocation = CGPointMake(location.x, myObject.center.y); 
    myObject.center = xLocation; 
    } 
} 

回答

1
CGPoint yLocation = CGPointMake(myObject.center.x, location.y); 
myObject.center = yLocation; 
+0

謝謝,謝謝,謝謝你! – blacksheep 2010-05-08 12:10:26

+0

不要感謝我;剛剛投票並接受答案。 ;-) – 2010-05-08 12:48:41

+0

好的。但我仍然有一個小問題:拖動是在該對象之外使用該代碼工作: - (void)touchesMoved:(NSSet *)與事件觸及:(UIEvent *)事件UITouch * touch = [[event allTouches] anyObject] ; CGPoint位置= [touch locationInView:touch.view]; CGPoint xLocation = CGPointMake(location.x,myObject.center.y); myObject.center = xLocation; } 但不是上面的代碼。 – blacksheep 2010-05-08 12:57:01