1

这个网站真的很棒。

这次我有一个简单的问题。我想将来自用户的任何滚动输入(可能是滚轮、触摸板等)传递给包含我自己的子视图的 NSScrollView。

目前,如果用户仅在 documentView 上滚动(在我的子视图框架之外),则滚动正常工作,但如果他们在光标位于子视图上时滚动,则不会发生任何事情。所以基本上我想让子视图识别滚动事件并将其传递回滚动视图。

任何帮助是极大的赞赏。

干杯。

编辑:这是我用来将子视图添加到 documentView 的代码.

-(void)useProject:(NSNumber *)projectId
{
[self resetView];

NSRect bounds = [[self view] bounds];
NSRect defaultFrame = NSMakeRect(20, NSMaxY(bounds)-93, NSMaxX(bounds)-20, 50);


//Prepare the milestone view
if (_milestoneView == nil)
    _milestoneView = [MilestoneView milestoneViewFromNibWithFrame:defaultFrame withProject:[BCLocalFetch projectForId:projectId]];
[_milestoneView reloadList];


//Prepare the activity view
if (_activityView == nil)
    _activityView = [ActivityView activityViewFromNibWithFrame:defaultFrame withProject:[BCLocalFetch projectForId:projectId]];

[self refresh];
}

然后,我使用刷新方法重新定位它们,因为内容大小会有所不同,所以我想要一个单独的方法。

-(void)refresh
{
//Position the milestones first
[_milestoneView setFrameOrigin:NSMakePoint(20, NSMaxY([[self view] bounds])-[_milestoneView frame].size.height-60)];
if ([[_milestoneView milestones] count] > 0)
    [[self view] addSubview:_milestoneView];

//Now the activity view
[_activityView setFrameOrigin:NSMakePoint(20, [_milestoneView frame].origin.y-[_activityView frame].size.height-20)];
[[self view] addSubview:_activityView];

[self autosizeView];
}

-(void)autosizeView
{
//Resize the view to accommodate all subviews
NSRect oldFrame = [[self view] frame];
CGFloat lastY = [_activityView frame].origin.y;
if (lastY < 0) {
    CGFloat newHeight = oldFrame.size.height + (-lastY);
    [[self view] setFrameSize:NSMakeSize(oldFrame.size.width, newHeight)];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"BBContentDidResizeNotification" object:self];
}
4

1 回答 1

0

好的,所以我回到了这个问题,终于解决了。实现实际上非常简单。我向 PXListView 添加了一个属性,以指向要滚动的 NSScrollView。然后我实现了 NSResponder 的 scrollWheel: 方法,如下所示:

-(void)scrollWheel:(NSEvent *)theEvent
{
    //Pass scrolling to the superview
    [_scrollHandler scrollWheel:theEvent];
}

一切都很好!

于 2011-04-29T03:06:39.573 回答