我有一个依赖于 C 回调方法从 macbook 的触控板检索多点触控信息的应用程序。这是我如何将这些数据传达给用户的截断版本:
在 MT2AppDelegate.h 中:
#import "MyView.h"
@interface MT2AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet NSTextField *L1;
IBOutlet MyView *MTView;
}
@property (retain, nonatomic) IBOutlet MyView *MTView;
@property (retain, nonatomic) IBOutlet NSTextField *L1;
在 MT2AppDelegate.m 中:
#import "etc. etc."
static MT2AppDelegate *sharedWithCAppDelegateReference;
@implementation MT2AppDelegate
@synthesize L1, MTView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
sharedWithCAppDelegateReference=self;
[L1 setStringValue:@"Hello"];//this works
[MTView drawRect2];//this also works
MTDeviceRef dev = MTDeviceCreateDefault();
MTRegisterContactFrameCallback(dev, callback);
MTDeviceStart(dev, 0);
}
int callback( int example, float etc) {
[sharedWithCAppDelegateReference->L1 setStringValue:@"hello"];//this works
[sharedWithCAppDelegateReference->MTView drawRect2];//this does NOT work
return 0;
}
因此,出于某种原因,在一个 IBOutlet 上使用函数可以在 C 中正常工作,而另一个则什么也不做。相同的两个函数都在 Objective-c 中工作。我似乎也无法从 C 中的应用程序委托调用函数。例如,[sharedWithCAppDelegateReference setPoint];
什么也不做。
此外,如果有更优雅的方式来做到这一点(我敢肯定有),我会全神贯注。这里发生的是这个回调函数不断更新,报告触控板上手指位置的信息。我想为视图设置动画,以便它提供手指位置的视觉表示。应用程序 FingerMgmt 在这方面做得很好,但没有可用的源代码。
我目前有我的应用程序委托,其中包含回调函数,以及另一个类(“MyView”),它是我的应用程序窗口中的视图类。应用程序委托通过界面构建器中的 IBOutlet 链接到视图,我计划将命令传递给它以更新代表手指的椭圆的位置。但同样,这对我不起作用。