나는 수퍼 뷰에서 마우스로 드래그 할 수있는 다양한 내용의 서브 클래 싱 된 NSViews (프레임)가있는 프로그램을 작성 중입니다. 모든 뷰에는 하나의 하위 뷰인 contentView가 포함되며이 뷰에는 차례로 복잡한 계층 구조가 포함될 수 있습니다.mouseDragged : 두 개의 하위보기로 전달되지 않습니까?
NSTextField를 contentView로 편집 할 수없는 경우 mouseDown : 및 mouseDragged : 이벤트가 문제없이 슈퍼 뷰로 전달되고 드래그하는 것이 정상적으로 작동합니다. 이벤트가 수퍼에 NSTextFields에서 전달되지 않습니다
mouseDown: ---> [NSTextField] ---> [Frame]
mouseDragged: ---> [NSTextField] ---> [Frame]
있는 contentView 차례로 NSTextFields의 mouseDragged의 숫자를 포함 NSView의의 서브 클래스 인 경우
.mouseDown: ---> [NSTextField] ---> [subclassed NSView] ---> [Frame]
mouseDragged: ---> [NSTextField] -x->
mouseDown : 이벤트가 프레임에 수신되었습니다. NSTextFields 사이의 간격을 클릭하고 contentView를 드래그하면 잘 작동합니다.
NSTextFields가있는 contentView에서 다음과 같이 설정됩니다 : 방법을 떠날뿐만 아니라 서브 클래 싱 NSTextField있는 및 서브 클래 싱 된 NSView의 모두 방법 : 나는의 mouseDragged를 추가하는 시도
NSTextField *textfield = [[NSTextField alloc] initWithFrame:rect];
[textfield setBordered:NO];
[textfield setSelectable:NO];
[textfield setEditable:NO];
[textfield setTextColor:[NSColor blackColor]];
[textfield setBackgroundColor:[NSColor clearColor]];
[textfield setDrawsBackground:NO];
[textfield setAlignment:NSRightTextAlignment];
[textfield setFont:[NSFont fontWithName:@"Helvetica" size:14]];
[self addSubview:textfield];
[textfield release];
. 어느 쪽도 차이를 만들지 않았습니다. 문제는 동일한 하위 뷰 수준에있는 다른 NSControl에도 있습니다. 순간
- (void)mouseDragged:(NSEvent *)theEvent
{
[super mouseDragged:theEvent];
}
또는
- (void)mouseDragged:(NSEvent *)theEvent
{
[self.superview mouseDragged:theEvent];
}
이 문제는 나에게 완전히 직관적 보인다. 제가 누락 된 것이 있습니까? (Mountain Lion의 Xcode 4.6.2로 작업 중입니다.)
나는이 접근법을 완전히 이해하지 못합니다. NSTextField가 이동을하는 NSView의 직접 하위 뷰인 경우 끌어서 드래그하면 제대로 작동하는 것 같습니다. 더 깊은 계층 구조를 도입 할 때만 문제가 시작됩니다. 또한, NSTextField NSResponder의 서브 클래스이기 때문에, 원래 질문에 언급 된 mouseDown/mouseDragged/mouseUp을 덮어 쓰지 않을 것인가? –
NSTextField에서 mouseDown :을 덮어 쓰고 mouseDown :을 호출하지 않은 것으로 보입니다. 다른보기에서는 mouseDragged : 및 mouseUp :이 호출되어 수퍼 뷰로 보내집니다. 물론이 경우 나는 드래그를 시작할 수 없습니다. –
링크에서 힌트를 구현하려고 시도했지만 "주소에 섹션의 개체 파일 섹션을 포함하지 않음"이라는 알림이 응용 프로그램과 충돌했습니다.mouseDown에 대한 코드는 다음과 같습니다. '메소드 nsviewMouseDownMethod = class_getClassMethod ([NSResponder class], @selector (mouseDown :)); IMP mouseDownImplememation = method_getImplementation (nsviewMouseDownMethod); mouseDownImplememation (self.superview, @selector (mouseDown :));' –