Нет прокрутки или взаимодействия с пользователем в новом NSWindow с NSScrollView - PullRequest
4 голосов
/ 27 января 2012

Я создаю приложение (без компоновщика интерфейса!), Которое «живет» в NSStatusBar; когда вы щелкаете по значку на панели состояния, появляется окно NSW с NSScrollView. Появляется окно, но кажется, что что-то мешает взаимодействию пользователя с ScrollView

Чтобы выяснить, из-за чего возникла проблема, я также добавил свое представление к контенту основных окон в AppDelegate. Странно то, что представление прокрутки является интерактивным в главном окне ... Любой знает, почему в моем новом не работает окно

Это код, который я использую для создания нового 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

И это код, который создает представление и 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

1 Ответ

1 голос
/ 28 января 2012

Вы можете изменить NSBackingStoreRetained на NSBackingStoreBuffered, как указано здесь: NSScrollView в NSWindow

...