Cocoa의 NSView가 미친듯한 마우스로운 이벤트를 얻는가?
문제
Hullo All- 나는 Mousedown에서 프로그래밍 방식으로 움직이는 nsview 서브 클래스를 가지고 있습니다. 작동하지만 이상한 부작용이 있습니다.
- 하위 뷰를 클릭합니다. 하위 뷰가 멀어집니다 좋은
- 잠시 기다립니다. 나는 마우스를 움직이지 않습니다. 하위 뷰가 움직여서 더 이상 내 커서 아래에 있지 않습니다.
- 마우스를 다시 클릭합니다.
- 기본 창이 Mousedown 이벤트를 얻을 것으로 기대하지만 (하위 뷰가 더 이상 내 커서 아래에 있지 않기 때문에) 내 하위 뷰는 어떻게 든이 이벤트를 얻습니다. 이상한
- Mousedown 이벤트는 클릭이 내 서브 클래스의 한계 외부에 있음을 분명히 보여줍니다. 이상한
- Mousedown 이벤트는 또한 마우스 클릭 사이에서 몇 초 동안 기다렸음에도 불구하고 클릭 카운트가 증가했음을 분명히 보여줍니다. 이상한
... 내가보고있는 것에 대한 설명이 있어야합니다. 내 코드는 다음과 같습니다. 단순히 "Oddmouse"라는 새로운 Cocoa 응용 프로그램 프로젝트를 작성하고 다음을 OddMouseAppDelegate.h 파일에 복사합니다.
#import <Cocoa/Cocoa.h>
@interface OddMouseAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end
@interface OddView : NSView {
}
@end
... 그리고 다음은 OddMouseAppDelegate.m 파일에 대한 다음과 같습니다.
#import "OddMouseAppDelegate.h"
@implementation OddMouseAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[Window ContentView] AddSubView : [[OddView Alloc] init]]; } @끝
@implementation OddView
- (id)init {
self = [super initWithFrame:NSMakeRect(100, 100, 100, 100)];
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
NSBezierPath *bz = [NSBezierPath bezierPathWithRoundedRect:[self bounds]
xRadius:9 yRadius:9];
[[NSColor blueColor] set];
[bz fill];
}
- (void)mouseDown:(NSEvent *)event {
NSPoint locationInMyself = [self convertPoint: [event locationInWindow]
fromView: nil];
NSLog(@"MOUSE DOWN COORDS: x=%f y=%f, count=%i",
locationInMyself.x, locationInMyself.y, [event clickCount]);
float newX = [self frame].origin.x+100;
float newY = [self frame].origin.y+100;
[self setFrame:NSMakeRect(newX, newY, 100, 100)];
}
@end
... 그런 다음 빌드 한 다음 달리고 목격하십시오! fwiw, 여기 콘솔에서 볼 수있는 내용은 다음과 같습니다.
10-01-15 11:38:24 PM OddMouse[4583] MOUSE DOWN COORDS: x=48.000000 y=56.000000, count=1
10-01-15 11:38:37 PM OddMouse[4583] MOUSE DOWN COORDS: x=-52.000000 y=-44.000000, count=2
10-01-15 11:38:44 PM OddMouse[4583] MOUSE DOWN COORDS: x=-152.000000 y=-144.000000, count=3
10-01-15 11:38:52 PM OddMouse[4583] MOUSE DOWN COORDS: x=-252.000000 y=-244.000000, count=4
10-01-15 11:39:03 PM OddMouse[4583] MOUSE DOWN COORDS: x=-352.000000 y=-344.000000, count=5
해결책
Freaking Heck- 이것은 더블 클릭 속도로 잘못 행동하는 것이 밝혀졌습니다. Prefs 변경 SFA를 변경했지만 재부팅이 해결되었습니다.
제휴하지 않습니다 StackOverflow