Objective c 在透明NSView窗口中的NSView中不工作的事件
我一直在使用这个代码Objective c 在透明NSView窗口中的NSView中不工作的事件,objective-c,cocoa,macos,Objective C,Cocoa,Macos,我一直在使用这个代码 static const CGFloat kSwipeGestureLeft = 1.0; static const CGFloat kSwipeGestureRight = -1.0; static const CGFloat kSwipeGestureUp = 1.0; static const CGFloat kSwipeGestureDown = -1.0; - (void)swipeWithEvent:(NSEvent *)event {
static const CGFloat kSwipeGestureLeft = 1.0;
static const CGFloat kSwipeGestureRight = -1.0;
static const CGFloat kSwipeGestureUp = 1.0;
static const CGFloat kSwipeGestureDown = -1.0;
- (void)swipeWithEvent:(NSEvent *)event {
if ([event deltaX] == kSwipeGestureLeft) {
NSLog(@"LEFT SWIPE!");
}
else if ([event deltaX] == kSwipeGestureRight) {
NSLog(@"RIGHT SWIPE!");
}
else if ([event deltaY] == kSwipeGestureUp) {
NSLog(@"UP SWIPE!");
}
else if ([event deltaY] == kSwipeGestureDown) {
NSLog(@"DOWN SWIPE!");
}
else {
[super swipeWithEvent:event];
}
}
在界面生成器中发送回的NSView中,在我通过代码使部分透明的窗口内然而,它**似乎只在不透明窗口内工作,而不是在透明窗口内
为什么??我怎样才能解决这个问题?如果我做不到这一点,我还能做吗,比如拍下整个屏幕的快照,然后将其设置为窗口的背景(稍微变暗)
我尝试将NSWindow**子类化并将其放入,但它仍然不起作用。
我使用的代码实际上并没有使窗口透明,只是将其背景色更改为透明:
//Set up the window
[window setLevel:kCGNormalWindowLevel];
[window setOpaque:NO];
[window setStyleMask:0];
[window setBackgroundColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.3]];
[window setAlphaValue:0];
//Resize the window to fill the screen
[window
setFrame:[window frameRectForContentRect:[[window screen] frame]]
display:YES
animate:YES];
//Fade the window in
[window makeKeyAndOrderFront:self];
[[window animator] setAlphaValue:1.0];
确保您的窗口实际上是关键窗口。也就是说,不要假设MakeKeyandDerfront成功地使您的窗口成为关键窗口。有关详细信息,请参阅-[NSWindow canBecomeKeyWindow]方法(您可能必须重写它,以便自定义窗口返回YES)。我以前在没有标题栏的windows上遇到过这个问题,不确定您是否遇到了相同(或类似)的问题。您使用的是UIgestureRecognitizer吗?这似乎是目前使用的最简单的方法:)不要将alpha设置为0,而是将其设置为一些较低的值,如0.01。对于完全透明的视图,事件将被忽略。您用来设置NSWindow不透明度的代码是什么?我现在已将其添加到问题中!:)从it的外观来看,似乎您正在尝试全屏显示视图。在这种情况下,您是否考虑过使用NSView的-enterFullScreenMode:withOptions:method而不是尝试使窗口填满屏幕?我覆盖了自定义窗口,也在窗口上称为“makeKeyWindow”,但它仍然不起作用(您是否在NSWindow子类中实现了canBecomeKeyWindow以始终返回YES?是否调用了它?我实现了canBecomeKeyWindow以始终返回YES,但当我调用makeKeyWindow时,它说它无法..在Mac OS X上没有
UIgestureRecognitor
。好的,我将透明度设置为0.01,但它没有dn没有帮助。不确定这是否有帮助,但请尝试在窗口上设置setIgnoresMouseEvents:YES。