2011-08-06 46 views

回答

1

如果你想移動整個文本字段,那麼您可以使用此代碼:

注意您必須聲明像userIsTouching一個布爾值,在你的頭

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    // Check if the user's touch is within the textfield 
    CGPoint touch = [[touches anyObject] locationInView:self.view]; 
    if (CGRectContainsPoint(textField.frame, touch)) { 
     userIsTouching = YES; 
    } 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    if (userIsTouching) { 
     textField.center = [[touches anyObject] locationInView:self.view]; 
    } 
} 

// Obviously, you then have to set the userIsTouching variable to NO when the user releases the touch 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    userIsTouching = NO; 
} 

類似的東西應該這樣做。

+0

感謝您的回覆 – praveen

相關問題