このサイトは本当に素晴らしいです。
今回はできれば簡単な質問があります。ユーザーからのスクロール入力(ホイール、タッチパッドなど)を、独自のサブビューを含む 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];
}