我有一个NSPageController
- 控制器,可让用户在水平视图之间滑动。
问题在于,我们滑动到的视图中的一个视图上有一个NSTableView
。
此时我无法刷回以前的视图,因为NSTableView
正在“吃掉”所有滑动手势。有没有人知道如何在NSTableView
上禁用仅水平滚动,以便水平滑动栅格会转到NSPageController
而不是表格的视图?
答案 0 :(得分:0)
试试这个
- (void)scrollWheel:(NSEvent *)theEvent
{
[self.nextResponder scrollWheel:theEvent];
}
希望它有所帮助。
答案 1 :(得分:0)
使用以下NSScrollView的自定义类实现
在Swift中解决class HorizontalScrollDisabledTable: NSScrollView {
var currentScrollIsHorizontal: Bool = true;
override func scrollWheel(theEvent: NSEvent) {
var phase: NSEventPhase = theEvent.phase
/* Ensure that both scrollbars are flashed when the user taps trackpad with two fingers */
if (phase == .MayBegin) {
super.scrollWheel(theEvent) ;
self.nextResponder?.scrollWheel(theEvent);
return;
}
/* Check the scroll direction only at the beginning of a gesture for modern scrolling devices */
/* Check every event for legacy scrolling devices */
if (phase == .Began || (phase == .None && theEvent.momentumPhase == .None)) {
currentScrollIsHorizontal = fabs(theEvent.scrollingDeltaX) > fabs(theEvent.scrollingDeltaY);
}
if (!currentScrollIsHorizontal ) {
super.scrollWheel(theEvent);
} else {
self.nextResponder!.scrollWheel(theEvent);
}
}
}
以下是上面的scrollWheel方法的相同答案的代码,但是在ObjectiveC中。
-(void)scrollWheel:(NSEvent *)theEvent {
NSEventPhase phase = [theEvent phase];
/* Ensure that both scrollbars are flashed when the user taps trackpad with two fingers */
if (phase == NSEventPhaseMayBegin) {
[super scrollWheel:theEvent];
[self.nextResponder scrollWheel:theEvent];
return;
}
/* Check the scroll direction only at the beginning of a gesture for modern scrolling devices */
/* Check every event for legacy scrolling devices */
if (phase == NSEventPhaseBegan || (phase == NSEventPhaseNone && theEvent.momentumPhase == NSEventPhaseNone)) {
currentScrollIsHorizontal = fabs(theEvent.scrollingDeltaX) > fabs(theEvent.scrollingDeltaY);
}
if (!currentScrollIsHorizontal ) {
[super scrollWheel:theEvent];
} else {
[self.nextResponder scrollWheel:theEvent];
}
}
答案 2 :(得分:-2)
创建一个bool,允许你的panGesture在panScrollView
内进行操作。
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.blockPanGesture = YES;
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:
(BOOL)decelerate
{
self.blockPanGesture = NO;
}
然后
-(void)panScrollView:(UIPanGestureRecognizer *)panGestureRecognizer
{
if(self.blockPanGesture == NO)
{
// do the stuff
}
}
如果您正在平移整个桌面视图,我会将手势识别器放在tableView本身上......否则还有
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
为您处理所有这些......但我假设您不想使用此功能。您也可以构建此逻辑,例如,您可能希望在scrollView也可以调整时进行调整,方法是将相似的检查放入 - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView等。