如何操作另一个类的变量

时间:2013-01-02 18:45:01

标签: objective-c

我正在编写QTMovieView的功能。我想双击QTMovieView使其退出全屏模式。 QTMovieView由AppController.m控制,我在AppController中编写exit fullscreenmode函数。因为我想捕获双击QTMovieView的事件。所以我必须覆盖mouseDown事件。覆盖功能写入" QTMovieView + TFOverrideDrag.h"

QTMovieView + TFOverrideDrag.m

#import "QTMovieView+TFOverrideDrag.h"
#include "AppController.h"


@implementation QTMovieView (TFOverrideDrag)

- (void)mouseDown:(NSEvent *)theEvent
{
   [self.superview becomeFirstResponder];
    NSInteger clickCount = [theEvent clickCount];
    if (2 == clickCount) {
        [AppController exitFullScreen:self];

        NSLog(@"SS");
    }
    NSLog(@"MDown");
}

并且此功能成功覆盖。但exitFullScreen函数失败。我该怎么解决?谢谢

更新

AppController.h

#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import <QTKit/QTKit.h>

@interface AppController : NSDocument
{
    QTMovie     *qtmovie;
    QTMovieView *_movieView;
}

@property (assign)  IBOutlet    QTMovieView *movieView;


- (IBAction)toggleFullscreen:(id)sender;
+(IBAction)exitFullScreen:(id)sender;

@end

AppController.m

#import "AppController.h"

@implementation AppController
@synthesize movieView=_movieView;


- (IBAction)toggleFullscreen:(id)sender
{

    _movieView=_movieView;
    NSDictionary *fullScreenOptions = [[NSDictionary dictionaryWithObject:[NSNumber     numberWithBool:YES]forKey:NSFullScreenModeSetting] retain];

    [_movieView enterFullScreenMode:[[NSScreen mainScreen] retain] withOptions:fullScreenOptions];

}

+(void)exitFullScreen:(id)sender
{
    _movieView=_movieView;
    NSLog(@"exitFullscreen");

    NSDictionary *fullScreenOptions = [[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]forKey:NSFullScreenModeSetting] retain];
    [_movieView exitFullScreenModeWithOptions:fullScreenOptions];
}
@end

2 个答案:

答案 0 :(得分:0)

您确定AppController声明类似+(void)exitFullScreen:的类方法吗?如果没有,那么您将需要将实例方法更改为类方法(使用+而不是-)或子类QTMovieView类并传递{{{}的实例1}}到实例。

答案 1 :(得分:0)

问题解决了!我解决了这个问题:

- (void)mouseDown:(NSEvent *)theEvent
{
   [self.superview becomeFirstResponder];
    NSInteger clickCount = [theEvent clickCount];
    if (2 == clickCount) {
        NSDictionary *fullScreenOptions = [[NSDictionary dictionaryWithObject:[NSNumber     numberWithBool:YES]forKey:NSFullScreenModeSetting] retain];
        [super enterFullScreenMode:[[NSScreen mainScreen] retain] withOptions:fullScreenOptions];
        NSLog(@"SS");
    }
    NSLog(@"MDown");
}    

关键是“超级”。

相关问题