代码之家  ›  专栏  ›  技术社区  ›  Rudolfs Bundulis

混合层支持视图与非层支持视图导致奇怪的窗口角落外界

  •  0
  • Rudolfs Bundulis  · 技术社区  · 6 年前

    所以,不幸的是,这是很难给出MVCE的情况之一,但我会尽量详细地描述每件事。

    所以我有一个程序构造的 NSWindow 像这样-

    _window = [[NSWindow alloc] initWithContentRect:_frameRect styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskTexturedBackground backing:NSBackingStoreBuffered defer:NO];
    if ([_window respondsToSelector:@selector(titlebarAppearsTransparent)])
    {
       _window.titlebarAppearsTransparent = true;
    }
    CGFloat x = (_window.screen.frame.size.width - _window.frame.size.width) / 2, y = (_window.screen.frame.size.height - _window.frame.size.height) / 2;
    [_window setFrameOrigin:NSMakePoint(x, y)];
    [[_window standardWindowButton:NSWindowZoomButton] setHidden: YES];
    [[_window standardWindowButton:NSWindowMiniaturizeButton] setHidden: YES];
    _window.backgroundColor = [NSColor colorWithHexColorString:@"f4f7fc"];
    

    然后我在程序上改变 contentView 通过设置不同的 NSView 内容视图的派生类。我总是同样地通过他们 _frameRect 在建造窗户时使用的。

    一切都很好,直到我添加了一个使用关键帧动画的类。我必须添加一个图层,现在-无论视图设置为 内容视图 在那之后,有奇怪的黑色角落出来的圆形窗口角落。错误视图的创建方式如下:

    -(instancetype)initWithFrame:(NSRect)frameRect
    {
       if (self = [super initWithFrame:frameRect])
       {
           self.wantsLayer = YES;
           _spinnerImageView = [[NSImageView alloc] initWithFrame:NSMakeRect(348, 342, 24, 24)];
           _spinnerImageView.wantsLayer = YES;
           [_spinnerImageView setLayer:[CALayer layer]];
           NSMutableArray<NSImage*>* images = [NSMutableArray arrayWithCapacity:30];
           for (NSUInteger spinnerImageIndex = 0; spinnerImageIndex < 30; ++spinnerImageIndex)
           {
               NSString* image = [NSString stringWithFormat:@“frame-%@“, @(spinnerImageIndex)];
               [images addObject:[NSImage imageNamed:image]];
           }
           _spinnerAnimation = [CAKeyframeAnimation animationWithKeyPath:kAnimationKey];
           [_spinnerAnimation setCalculationMode:kCAAnimationDiscrete];
           [_spinnerAnimation setDuration:0.75f];
           [_spinnerAnimation setRepeatCount:HUGE_VALF];
           [_spinnerAnimation setValues:images];
           [self addSubview:_spinnerImageView];
           _pleaseWaitText = [NSAttributedString viewTitleWithText:@“Please wait...“];
           [self resetToInitialState];
           _loadingButton = [[DisabledButton alloc] initWithFrame:NSMakeRect(288, 16, 144, 32) andText:@“Please wait...“];
           [self addSubview:_loadingButton];
       }
       return self;
    }
    

    所以发生的事情是,有动画的屏幕看起来很漂亮(注意角落): Window with correct corners 在我从那个视图导航到一个没有 wantsLayer 设置为 YES 我得到腐败的角落: enter image description here 这只是一个例子,但基本上从带有动画的视图导航到任何其他视图都会导致黑色边框。

    现在我试着去阅读图层系统,但是我不能准确地指出我到底做错了什么。我假设混合非层支持和层支持的视图正在扰乱某些东西,但是设置时 wantsLayer公司 对于所有视图,我得到不同的工件。我真的希望黑色角落的东西是会触发一个“哦,这是由”反射在某人更有经验的可可。

    0 回复  |  直到 6 年前
    推荐文章