I'm having trouble getting a scrollview (within a table view) to scroll. Basically, I have an if statement which checks if horizontal movement is greater than vertical movement. If it is, a pan gesture is executed on the cell. Else, I would like the tableview to scroll as normal. I've tried using some variation of self.scrollview.enabled = yes
but I couldn't get it working.
It works fine for the horizontal pan gesture, but I can't get it to scroll properly in the else section. Here's the most relevant code: (sorry if it's terrible - I'm still new to iOS/Objective C). Oh and if you see a strange 'code' randomly in the code extract, ignore it - I had some trouble formatting and I lost a word.
-(void)handlePan:(UIPanGestureRecognizer *)panGestureRecognizer
{
CGPoint location = [panGestureRecognizer locationInView:_tableView];
//Get the corresponding index path within the table view
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:location];
TVTableCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
CGPoint translation = [panGestureRecognizer translationInView:cell];
// Check for horizontal gesture
if (fabsf(translation.x) > fabsf(translation.y)) {
CGPoint originalCenter = cell.center;
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
NSLog(@"pan gesture started");
}
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
// translate the center
CGPoint translation = [panGestureRecognizer translationInView:self.view];
if (translation.x > 0) {
cell.center = CGPointMake(originalCenter.x + (translation.x-(translation.x-3)), originalCenter.y);
} else {
cell.center = CGPointMake(originalCenter.x + (translation.x-(translation.x+3)), originalCenter.y);
}
// determine whether the item has been dragged far enough to initiate a delete / complete
//this will be implemented eventually
// _deleteOnDragRelease = self.frame.origin.x < -self.frame.size.width / 2;
NSLog(@"state changed");
}
if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
// the frame this cell would have had before being dragged
CGRect originalFrame = CGRectMake(0, cell.frame.origin.y,
cell.bounds.size.width, cell.bounds.size.height);
// if (!_deleteOnDragRelease) {
// if the item is not being deleted, snap back to the original location
[UIView animateWithDuration:0.2
animations:^{
cell.frame = originalFrame;
}
];
}
} else {
//else: scroll tableview normally
NSLog(@"dear god act normally");
}
}
Thanks for the help, all suggestions are very welcome.