在低分辨率屏幕

时间:2017-05-02 11:08:47

标签: drawrect menubar nsscrollview nsmenu nsmenuitem

当我在低分辨率屏幕上使用我的菜单栏应用程序时,我有一些小故障。请看下面的截图作为插图!由于低分辨率屏幕的高度降低,我的整个NSMenu不适合屏幕,所以自动滚动视图出现,所以我仍然可以获得所有不同的项目。

问题是我的cutom NSMenuItems因此具有自己的draw [drawRect:(NSRect)dirtyRect]方法的自定义NSViews,在向下滚动和备份时表现出一些小问题。它似乎缺少一些绘图调用。遗憾的是,我不知道如何检测NSMenu何时有效滚动,或者只是在NSMenu类上访问这个自动创建的scrollview ...

非常感谢任何帮助!

我的NSMenuItem视图的绘图代码。

- (void)drawRect:(NSRect)dirtyRect
 {
if (self.enabled)
{
    if (self.isHighlighted)
    {
        [self colorRectHighlighted:dirtyRect];

        [self drawTextInRect:dirtyRect withState:CustomCheckMenuItemViewStateHiglighted];

        [self drawStateIconWithColor:[NSColor whiteColor]];
    }
    else
    {
        [self drawTextInRect:dirtyRect withState:CustomCheckMenuItemViewStateNormal];

        AppDelegate *appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
        if(appDelegate.menuIsInDarkMode)
        {
            [self drawStateIconWithColor:[NSColor colorWithWhite:1.0 alpha:0.9]];
        }
        else
        {
            [self drawStateIconWithColor:[NSColor selectedMenuItemIndicatorColor:([NSColor currentControlTint]==NSBlueControlTint)?YES:NO]];
        }
    }
}
else
{
    [self drawTextInRect:dirtyRect withState:CustomCheckMenuItemViewStateNormal];

    AppDelegate *appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
    if(appDelegate.menuIsInDarkMode)
    {
        [self drawStateIconWithColor:[NSColor colorWithRed:136/256.0 green:136/256.0 blue:136/256.0 alpha:0.9]];
    }
    else
    {
        [self drawStateIconWithColor:[NSColor colorWithWhite:0 alpha:0.1]];
    }
}

}

编辑:

我用滑块初始化NSMenuItems:

self.tiltSliderViewController = [[SlidingViewController alloc] initWithNibName:@"SlidingViewController" bundle:nil];
self.tiltSliderViewController.delegate = self;
[tiltSliderMenuItem setView:[self.tiltSliderViewController view]];

self.rotationSliderViewController = [[SlidingViewController alloc] initWithNibName:@"SlidingViewController" bundle:nil];
self.rotationSliderViewController.delegate = self;
[rotationSliderMenuItem setView:[self.rotationSliderViewController view]];

此处使用的viewcontrollers具有以下实现:

@interface SlidingViewController ()

@end

@implementation SlidingViewController

- (IBAction)valueChanged:(id)sender
{
    float slider_value = [_slider floatValue];
    [_slider setToolTip:[NSString stringWithFormat:@"%ld", 
_slider.integerValue]];

    [_delegate sliderValueChanged:slider_value sender:self];
}

@end

截图:

正常

enter image description here

DOWN

enter image description here

UP AGAIN = GLITCH !!

enter image description here

0 个答案:

没有答案