我有一个 NSWindowController,我在其中添加了相应的 ViewController。我想在其中一个 ViewController 中处理触摸事件。我的课是
窗口.h
@interface WindowController : NSWindowController<NSToolbarDelegate>
@property (nonatomic, strong) NSViewController *currentViewController;
@property (assign) IBOutlet NSView *targetView;
@end
窗口.m
-(void)addViewController
{
NSViewController *currentController = [[currentControllerClass alloc]initWithNibName:controllerIdentifier bundle:nil];
self.currentViewController = currentController;
[self.targetView addSubview:self.currentViewController.view];
[self.currentViewController.view setFrame: [self.targetView bounds]];
}
-(void) awakeFromNib{
[super awakeFromNib];
[self.window setIgnoresMouseEvents:NO];
[self setToolbarToPracticeView];
}
-(void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"Window > Mouse down");
}
我可以在这里打印 mousedown 事件。现在我有一个viewController,它是
视图控制器.h
@interface ViewController : NSViewController
@end
视图控制器.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
}
return self;
}
-(void)awakeFromNib
{
[self.view setAcceptsTouchEvents:YES];
}
-(BOOL)acceptsFirstResponder
{
return YES;
}
-(void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"ViewController > mouse down");
}
我想在 ViewController 中控制 mouseDown。我在这里错过了什么吗?
谢谢。