Objective c 在带有NSScrollView的新NSWindow中没有滚动或用户交互

Objective c 在带有NSScrollView的新NSWindow中没有滚动或用户交互,objective-c,cocoa,nswindow,nsscrollview,Objective C,Cocoa,Nswindow,Nsscrollview,我正在构建一个应用程序(没有界面生成器!),它“生活”在NSStatusBar中;单击状态栏中的图标时,将显示一个带有NSScrollView的NSWindow。窗口出现了,但似乎有什么东西阻止了用户与ScrollView的交互 为了找出问题的根源,我还将我的视图添加到AppDelegate中的主windows contentView中,奇怪的是scrollview在主窗口中是交互式的。。。有人知道为什么我的新窗口不工作吗 这是我用来创建新TTDropDownWindow的代码: -(无效)打开

我正在构建一个应用程序(没有界面生成器!),它“生活”在NSStatusBar中;单击状态栏中的图标时,将显示一个带有NSScrollView的NSWindow。窗口出现了,但似乎有什么东西阻止了用户与ScrollView的交互

为了找出问题的根源,我还将我的视图添加到AppDelegate中的主windows contentView中,奇怪的是scrollview在主窗口中是交互式的。。。有人知道为什么我的新窗口不工作吗

这是我用来创建新TTDropDownWindow的代码:

-(无效)打开窗口{
//下拉列表
如果(self.dropDownWindow==nil){
self.dropDownWindow=[[TTDropDownWindow alloc]init];
self.dropDownWindow.releasedWhenClosed=否;
self.dropDownWindow.contentView=self.view;
self.dropDownWindow.backgroundColor=[NSColor clearColor];
self.dropDownWindow.delegate=self;
self.dropDownWindow.alphaValue=1;
self.dropDownWindow.hasShadow=否;
self.dropDownWindow.不透明=否;
}
[[NSApplication sharedApplication]激活其他应用程序:是];
NSRect statusBarContentRect=self.statusBarItemView.window.frame;
NSPoint statusBarOriginPoint=NSMakePoint(NSMidX(statusBarContentRect)、NSMinY(statusBarContentRect));
NSRect screenFrame=self.dropDownWindow.screen.frame;
NSRect dropDownContentRect=NSZeroRect;
dropDownContentRect.size.width=下拉宽度;
dropDownContentRect.size.height=下拉高度;
dropDownContentRect.origin.x=statusBarOriginPoint.x-下拉宽度/2;
dropDownContentRect.origin.y=屏幕框.size.height-下拉高度-NSStatusBar.systemStatusBar.thickness;
[self.dropDownWindow设置框:dropDownContentRect显示:是];
[self.dropdownWindowMakeKeyandDerfront:nil];
}
这是TTDropDownWindow的实现:

#导入“TTDropDownWindow.h”
#导入“WFConstants.h”
@下拉窗口的实现
-(id)init
{
self=[super initWithContentRect:nsmakerrect(0,0,下拉宽度,下拉高度)样式掩码:NSBorderlessWindowMask backing:NSBackingStoreRetained defer:NO];
回归自我;
}
-(BOOL)可以成为主窗口{
返回YES;
}
-(BOOL)可以成为钥匙窗{
返回YES;
}
@结束
这是创建视图和滚动视图的代码

#导入“TTStatusBarDropDownView.h”
#导入“TTTestView.h”
@实现TTStatusBarDropDownView
@综合dropDownTableViewData=dropDownTableViewData;
-(id)initWithFrame:(NSRect)frameRect{
self=[super initWithFrame:frameRect];
如果(自我){
NSImageView*imageView=[[NSImageView alloc]initWithFrame:frameRect];
imageView.image=[NSImage ImageName:@“背景下拉列表”];
[自添加子视图:图像视图];
//首先创建一个视图以放入滚动视图中
NSView*scrollViewHolder=[[TTTestView alloc]initWithFrame:NSMakeRect(19,98,414,543)和Color:[NSColor yellowColor]];
[自添加子视图:scrollViewHolder];
//创建滚动视图
NSScrollView*scrollView=[[NSScrollView alloc]initWithFrame:NSMakeRect(0,0414543)];
scrollView.hasVerticalRuler=是;
scrollView.hasVerticalScroller=是;
[scrollViewHolder添加子视图:scrollView];
//TTTestView只是一个带有背景图形的NSView
TTTestView*滚动视图=[[TTTestView alloc]initWithFrame:NSMakeRect(0,0,200,10000)和颜色:[NSColor blueColor]];
[滚动添加子视图的视图:[[TTTestView alloc]initWithFrame:nsMakeCrect(10,10,100,8000)和颜色:[NSColor grayColor]];
[滚动视图设置文档视图:滚动的视图];
}
回归自我;
}
@结束

您可以将nsbackingstorereserved更改为NSBackingStoreBuffered,如下所述:

我不为mac OS编写代码,只为iOS移动设备编写代码,但也许你的ScrollView不是第一响应程序?你需要以编程方式设置吗?我认为不是,但我有一些情况,我的ViewObject不是第一响应程序,因此我必须对它们进行设置。这就解决了问题,所以无论何时创建窗口!使用NSBackingStoreBuffered模式!谢谢你的帮助!