2012-01-27 59 views
4

我正在建立一个应用程序(没有界面生成器!)'住'在NSStatusBar;当你点击StatusBar中的一个图标时,出现一个带有NSScrollView的NSWindow。该窗口出现,但似乎有什么阻止用户与ScrollView的交互没有滚动或新的NSWindow与NSScrollView中的用户交互

要找出问题来自哪里,我也添加了我的视图到AppDelegate的主窗口contentView中,奇怪的是scrollview是交互式的MainWindow ...任何人都知道为什么它在我的新窗口中不起作用?

这是我用它来创建新的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 

这是创建视图和滚动型

代码
#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 
+0

我不为Mac OS代码,只为iOS移动设备,但也许是你的ScrollView不是firstResponder? – matzino 2012-01-27 11:46:46

+1

你是否需要以编程方式设置? – Jankeesvw 2012-01-27 12:00:19

+0

我认为不是,但我有一些情况下,我的ViewObject不是第一个响应者,因此我必须将它们设置为explixit。 http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#jumpTo_88 – matzino 2012-01-27 13:16:07

回答

1

您可能会将NSBackingStoreRetained更改为NSBackingStoreBuffered a s在这里陈述: NSScrollView in a NSWindow

+1

这解决了这个问题,所以无论何时你创建一个窗口!使用NSBackingStoreBuffered模式!感谢您的帮助! – Jankeesvw 2012-01-28 13:59:23