轻扫以删除embedded在UIScrollView中的UITableView
我遇到了与UIScrollview相同的问题, 通过刷卡启用删除行
这是一个tableView和另一个视图作为一个scrollView子视图,我不能启用“滑动删除”,直到我设置scrollView的scrollEnable属性为NO ,但它带来了另一个问题:我不能滑动tableView和另一个视图
除了设置scrollEnable属性来启用“滑动删除”还有其他的方法吗?
如果没有,我应该什么时候应该设置self.scrollEnable = NO
,什么时候应该设置self.scrollEnable = YES
,让“滑动删除”和“滑动视图”都工作正常?
谢谢
如果我没有弄错,那么scrollview消耗的是触摸,桌子的编辑没有发生,因为桌子没有触及。 这可以通过子类化UIScrollView来解决,以便触及下一个响应者。 所以这只是一个覆盖触碰开始,移动和结束的问题。 今天晚些时候将更新答案与我现在在路上所需的代码。 干杯!
编辑:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.nextResponder touchesBegan:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(!self.dragging) { [self.nextResponder touchesMoved:touches withEvent:event]; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self.nextResponder touchesEnded:touches withEvent:event]; }
只需创build一个从UIScrollView
inheritance的类,并在实现中删除此代码。 这将使scrollView不能吞咽触摸,但传递它们。 显然,在创buildscrollView时,使用刚创build的类而不是UIScrollView
。 抱歉耽搁了。 希望这可以帮助。
干杯!
我已经成功地使用了
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
在包含tableview的UIScrollView子类中,使得驻留在tableview中的UISwipeGestureRecognizer能够被触发,而不是被“主”滚动视图的手势识别器所吞噬。
你需要使用UIScrollView
自定义子类。 它应该在水平滚动视图中的表视图中工作:
@interface MyCoolScrollView : UIScrollView @end @implementation MyCoolScrollView // Allows inner UITableView swipe-to-delete gesture - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer { return [otherGestureRecognizer.view.superview isKindOfClass:[UITableView class]]; } @end
@ THOR的答案是好的,但如果你的UITableView
是在UIScrollView
,你可能有另一个UIView
在那里。 当你在tableview
上向上滚动,你不小心滑到“其他视图”。
这将防止滑动,并允许您滑动删除。
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if (gestureRecognizer.state != 0) { return YES; } else { return NO; }
}
- 试图在Swift 2.0中设置UIDatePicker的时间
- 调用时出现“Error Code 8” – iOS
- 如何在uiwebview中调用https url?
- 操作button不会出现在通知iOS 10中
- 我怎么知道我是否使用私有框架?
- 如何通过货币代码设置iOS NSNumberFormatter区域设置?
- 在Google Play服务中邀请朋友
- 调整captureStillImageBracketAsynchronouslyFromConnection提供的CMSampleBufferRef:withSettingsArray:completionHandler:
- 在IOS MapView中,是否有注释标题callback函数或设置目标的方法?