Reputation: 476
I m iOS beginner and i have created following hierarchy,
1. uiview
2. uiview
3. uitextview
The size of uitextview and uiview(2) is same.
The question is, i want to make the uiview draggable by dragging on uitextview...???
I have tried this following but it cant works for me..
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *aTouch = [touches anyObject];
CGPoint location = [aTouch locationInView:self.noteTextView];
[UIView beginAnimations:@"Dragging A DraggableView" context:nil];
self.frame = CGRectMake(location.x, location.y, self.frame.size.width, self.frame.size.height);
[UIView commitAnimations];
}
here noteTextView is an object of UITextView..
Upvotes: 1
Views: 1321
Reputation: 5835
To drag a view you can use the following code (from ray's tutorial):
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
remember to enable user interaction on the view.
Also, not sure what you are doing but it sounds like you want to use a label not a UITextView.
Upvotes: 1