我遇到了麻烦(表视图中),滚动型滚动。 基本上,我有一个if语句,其检查是否水平运动大于垂直运动更大。 如果是,泛手势的细胞执行。 否则,我想实现代码如下滚动正常。 我一直在使用的某种变体试图self.scrollview.enabled = yes
,但我无法得到它的工作。
它工作正常的水平平移手势,但我不能让它在其他部分正常滚动。 这里是最相关的代码:(抱歉,如果这是可怕的 - 我还是新到iOS /目标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");
}
}
感谢您的帮助,所有的建议都非常欢迎。