我无法让滚动视图(在表格视图中)滚动。基本上,我有一个 if 语句来检查水平移动是否大于垂直移动。如果是,则在单元格上执行平移手势。否则,我希望表格视图正常滚动。我试过使用一些变体,self.scrollview.enabled = yes
但我无法让它工作。
它适用于水平平移手势,但我无法让它在 else 部分正确滚动。这是最相关的代码:(对不起,如果它很糟糕 - 我还是 iOS/Objective C 的新手)。哦,如果您在代码摘录中随机看到一个奇怪的“代码”,请忽略它——我在格式化时遇到了一些问题,我丢了一个字。
-(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");
}
}
感谢您的帮助,非常欢迎所有建议。