I have an NSView with a QTMovieView in it. My QTMovieView is intended to display a movie only; I do not want the user to be able to interact with it in any way. After a disappointing search for how to disable dragging the QTMovieView, I came across this workaround, which I implemented as a category on QTMovieView. It is intended to override the mouse events of the QTMovieView and is successful in preventing the user from being able to drag it or click the QTMovieView to pause it:
//QTMovieView+TFOverrideDrag.h
#import <QTKit/QTKit.h>
@interface QTMovieView (TFOverrideDrag)
- (void)mouseDown:(NSEvent *)theEvent;
- (void)mouseDragged:(NSEvent *)theEvent;
- (void)rightMouseDown:(NSEvent *)theEvent;
@end
...
//QTMovieView+TFOverrideDrag.m
#import "QTMovieView+TFOverrideDrag.h"
@implementation QTMovieView (TFOverrideDrag)
- (void)mouseDown:(NSEvent *)theEvent
{
[self.superview becomeFirstResponder];
NSLog(@"MDown");
}
- (void)mouseDragged:(NSEvent *)theEvent
{
[self.superview becomeFirstResponder];
NSLog(@"MDrag");
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
[self.superview becomeFirstResponder];
NSLog(@"RMouse");
}
@end
This is effective in preventing the user from dragging or pausing the movie, and the NSLog statements are being called appropriately.
The problem is that, after clicking on the QTMovieView, the QTMovieView's superview stops responding to keyboard events (keyDown). This is why I included the [self.superview becomeFirstResponder];
line in each of the QTMovieView's overridden methods in the category. This did not fix the problem.
It's worth noting that the QTMovieView's superview has subviews other than QTMovieView, some of which are drawn on top of the QTMovieView. When those are clicked, the QTMovieView does not cause any issues, and the program continues to run fine. However, the NSLog statements are still called in this situation.
I am convinced that it is indeed the QTMovieView that is causing the problem because I have run the program after removing it, and all clicks in that area cause no problems.
My questions boil down to these: Does anyone have a more reasonable workaround than overriding the mouse events for the QTMovieView to prevent user interaction? And if not, does anyone know why clicks within the frame of the QTMovieView would cause its superview to stop responding to the keyboard? Or, if there is a different class that could be used other than QTMovieView, I'd be open to that, although I do need to take advantage of the QTMovieLoopsAttribute, so any other class would need to provide that functionality.
After some further considering, I found a solution. I needed to override one more QTMovieView method in my category:
- (void)keyDown:(NSEvent *)theEvent
{
[self.nextResponder keyDown:theEvent];
NSLog(@"keyDown");
}
The log statement is not called for keyDown events until I have clicked in the QTMovieView's frame. Once I do (which is when my keyDown events previously started to be ignored by the superview), the log statement is called. However, now that I'm passing the keyDown event to nextResponder, the superview is responding appropriately. I am still annoyed about the need for such a convoluted workaround, so if anyone has something a bit more elegant, please do share! Until then, I hope that this can help anyone else running into similar issues!