Custom NSWindow setAlphaValue and makeKeyAndOrderFront
I have a custom window (matt gemells Transparent Window class) and I need to change the window's alpha value to achieve a fade in/out effect and perform a "makeKeyAndOrderFront:".
However this does not work.
What I did:
I imported 开发者_StackOverflowthe header:
#import "TransparentWindow.h"
Then tried:
[TransparentWindow setAlphaValue:0.5];
[TransparentWindow makeKeyAndOrderFront:self];
This gave me a warning that "Transparent Window" may not respond to either of the code above. So I attempted to implement the "setAlphaValue" into Transparent Window by adding:
- (void)setAlphaValue:(CGFloat)windowAlpha
{
[super setAlphaValue:windowAlpha];
}
but the 2 warnings won't go away. How can I fix this?
[TransparentWindow setAlphaValue:0.5]; [TransparentWindow makeKeyAndOrderFront:self];
This gave me a warning that "Transparent Window" may not respond to either of the code above.
That's because it (the TransparentWindow class) doesn't.
You need to send those messages to a TransparentWindow instance, not to the TransparentWindow class.
So I attempted to implement the "setAlphaValue" into Transparent Window by adding:
- (void)setAlphaValue:(CGFloat)windowAlpha { [super setAlphaValue:windowAlpha]; }
If this NSWindow method had not existed, calling it from a method in a subclass would not solve that problem.
精彩评论