No scrolling or user interaction in the new NSWindow with NSScrollView

I am creating an application (without an interface builder!) That "lives" in the NSStatusBar; when you click on the icon in the StatusBar, an NSWindow with NSScrollView appears. A window will appear, but it seems that something is interfering with the user’s interaction with ScrollView

To find out where the problem came from, I also added my view to the main contentView window in AppDelegate, it is strange that scrollview is interactive in MainWindow ... Does anyone know why it doesn't work in my new window?

This is the code I'm using to create a new 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]; } 

This is the implementation of 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 

And this is the code that creates the View and 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 
+4
source share
1 answer

You can change NSBackingStoreRetained to NSBackingStoreBuffered as indicated here: NSScrollView in NSWindow

+1
source

Source: https://habr.com/ru/post/1393341/


All Articles