Исчезните В/Постепенно исчезать для MAAttachedWindow

Я должен согласиться с Chris. Помните, не оптимизируйте, пока Вы на самом деле не должны будете делать так. Я действительно сомневаюсь, что проверка существование будет узким местом в любой разумной программе.

я действительно видел http://code.activestate.com/recipes/52558/ как способ сделать это, также. Непрокомментированная копия того кода ("спам" является просто случайным методом интерфейс класса, имеет):

class Singleton:
    class __impl:
        def spam(self):
            return id(self)
    __instance = None
    def __init__(self):
        if Singleton.__instance is None:
            Singleton.__instance = Singleton.__impl()
        self.__dict__['_Singleton__instance'] = Singleton.__instance
    def __getattr__(self, attr):
        return getattr(self.__instance, attr)
    def __setattr__(self, attr, value):
        return setattr(self.__instance, attr, value)

7
задан indragie 10 October 2009 в 18:20
поделиться

1 ответ

I'm not especially well versed in CoreAnimation and the usage of implicit animations. However, I was able to get the MAAttachedWindow to fade in by adding an explicit alphaValue property to the MAAttachedWindow class:

@interface MAAttachedWindow : NSWindow {
    CGFloat _alphaValue;
...
}
-(CGFloat) alphaValue;
-(void) setAlphaValue:(CGFloat)windowAlpha;
...

@implementation MAAttachedWindow

- (CGFloat) alphaValue {
 return _alphaValue;
}

- (void) setAlphaValue:(CGFloat)windowAlpha {
    _alpha = windowAlpha;
 [super setAlphaValue:windowAlpha];
}
...

By adding that, I was able to get the implicit animation for setAlphaValue to work:

(below code cribbed from Matt's Sample "NSStatusItemTest" code)

- (void)toggleAttachedWindowAtPoint:(NSPoint)pt
{
...
    [attachedWindow makeKeyAndOrderFront:self];
 [[attachedWindow animator] setAlphaValue:1.0];

I am not sure why explicitly defining the alphaValue property works. I would expect the inherited version from NSWindow would be invoked for the implicit animation. It doesn't appear to though.

5
ответ дан 6 December 2019 в 15:23
поделиться