I am working on an iPhone application where I want to drag a table view (not a cell) to a specific point on the screen. I have a table sitting in the lower half of the screen, and I have an image in the upper half.
When I look at the table to see the rows below, the table should actually move up above the image (y pos decreases and the height increases). The table will rise until it fills the entire screen, leaving a few pixels for the image, and it will be there as a docking station, and from that moment, the table should scroll. The same behavior is expected for scrolling down.
This may seem a little strange, but this is the new iOS template that is appearing.
I managed to complete the first part using the code snippet below.
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanForScrollView:)]; panGestureRecognizer.maximumNumberOfTouches = 1; panGestureRecognizer.delegate = self; panGestureRecognizer.minimumNumberOfTouches = 1; [self.tableView addGestureRecognizer:panGestureRecognizer]; - (void)handlePanForScrollView:(UIPanGestureRecognizer *)gesture { switch (gesture.state) { case UIGestureRecognizerStateBegan: break; case UIGestureRecognizerStateChanged: { CGPoint movement = [gesture translationInView:self.view]; CGRect frame = self.tableView.frame; frame.origin.y += movement.y; if(frame.origin.y >= Y_OFFSET && frame.origin.y < self.original_frame.origin.y){ frame.size.height -= movement.y; self.tableView.frame = frame; [gesture setTranslation:CGPointZero inView:self.view]; } break; } case UIGestureRecognizerStateEnded: case UIGestureRecognizerStateCancelled:{
This works fine, and the table moves up and docks below Y_OFFSET. But, as you could imagine, the table no longer scrolls.
So i tried this
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if(self.tableView.frame.origin.y <= Y_OFFSET || self.tableView.frame.origin.y >= self.original_frame.origin.y){ NSLog(@"Here"); return YES; } return NO; }
A message is printed here on the console, but the table does not scroll.
I even tried using panGestureRecognizer for a UITableView instead of my UIPanGestureRecognizer.
self.tableView.panGestureRecognizer addTarget:self action:@selector(handlePanForScrollView:)
But now the table scrolls and moves up.
"I want the table not to scroll, but to move to a certain point on the screen, and then stop moving and start scrolling."
What is the best way to handle this?
Greetings