gpt4 book ai didi

objective-c - 使用 NSScrollView 在新的 NSWindow 中没有滚动或用户交互

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:17 24 4
gpt4 key购买 nike

我正在构建一个“存在于”NSStatusBar 中的应用程序(没有界面构建器!);当您单击 StatusBar 中的图标时,会出现带有 NSScrollView 的 NSWindow。窗口出现,但似乎有什么东西阻止了用户与 ScrollView 的交互

为了找出问题出在哪里,我还在 AppDelegate 的主窗口 contentView 中添加了我的 View ,奇怪的是 ScrollView 在 MainWindow 中是交互式的......任何人都知道为什么它在我的新窗口中不起作用 window ?

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

- (void)openWindow {
// Dropdown
if (self.dropDownWindow == nil) {
self.dropDownWindow = [[TTDropDownWindow alloc] init];
self.dropDownWindow.releasedWhenClosed = NO;
self.dropDownWindow.contentView = self.view;
self.dropDownWindow.backgroundColor = [NSColor clearColor];
self.dropDownWindow.delegate = self;
self.dropDownWindow.alphaValue = 1;
self.dropDownWindow.hasShadow = NO;
self.dropDownWindow.opaque = NO;
}

[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
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 = DROP_DOWN_WIDTH;
dropDownContentRect.size.height = DROP_DOWN_HEIGHT;
dropDownContentRect.origin.x = statusBarOriginPoint.x - DROP_DOWN_WIDTH / 2;
dropDownContentRect.origin.y = screenFrame.size.height - DROP_DOWN_HEIGHT - NSStatusBar.systemStatusBar.thickness;

[self.dropDownWindow setFrame:dropDownContentRect display:YES];
[self.dropDownWindow makeKeyAndOrderFront:nil];
}

这是 TTDropDownWindow 的实现:

#import "TTDropDownWindow.h"
#import "WFConstants.h"

@implementation TTDropDownWindow

- (id) init
{
self = [super initWithContentRect:NSMakeRect(0, 0, DROP_DOWN_WIDTH, DROP_DOWN_HEIGHT) styleMask:NSBorderlessWindowMask backing:NSBackingStoreRetained defer:NO];
return self;
}

- (BOOL)canBecomeMainWindow {
return YES;
}

- (BOOL)canBecomeKeyWindow {
return YES;
}


@end

这是创建 View 和 ScrollView 的代码

#import "TTStatusBarDropDownView.h"
#import "TTTestView.h"

@implementation TTStatusBarDropDownView

@synthesize dropDownTableViewData = dropDownTableViewData_;


- (id)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if (self) {
NSImageView *imageView = [[NSImageView alloc] initWithFrame:frameRect];
imageView.image = [NSImage imageNamed:@"background-dropdown"];
[self addSubview:imageView];

// first create a view to put in a ScrollView
NSView *scrollViewHolder = [[TTTestView alloc] initWithFrame:NSMakeRect(19, 98, 414, 543) andColor:[NSColor yellowColor]];
[self addSubview:scrollViewHolder];

// create the scrollView
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 414, 543)];
scrollView.hasVerticalRuler = YES;
scrollView.hasVerticalScroller = YES;
[scrollViewHolder addSubview:scrollView];

// TTTestView is just a NSView with a background drawing
TTTestView *theViewThatScrolls = [[TTTestView alloc] initWithFrame:NSMakeRect(0, 0, 200, 10000) andColor:[NSColor blueColor]];
[theViewThatScrolls addSubview:[[TTTestView alloc] initWithFrame:NSMakeRect(10, 10, 100, 8000) andColor:[NSColor grayColor]]];

[scrollView setDocumentView:theViewThatScrolls];
}

return self;
}

@end

最佳答案

您可以按照此处所述将 NSBackingStoreRetained 更改为 NSBackingStoreBuffered: NSScrollView in a NSWindow

关于objective-c - 使用 NSScrollView 在新的 NSWindow 中没有滚动或用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9032619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com