NSInvocation 回调使用

来源:互联网 发布:旋转矩阵计算器 编辑:程序博客网 时间:2024/06/05 09:40
声明
NSInvocation* m_touchDown;


赋值
-(void) setTouchMoveCallback:(id) target sel:(SEL) sel {    if (m_touchMove) {        [m_touchMove release];        m_touchMove = nil;    }    NSMethodSignature *sig= [target methodSignatureForSelector:sel];    NSAssert(sig, @"");    m_touchMove = [NSInvocation invocationWithMethodSignature:sig];    [m_touchMove setTarget:target];    [m_touchMove setSelector:sel];    [m_touchMove setArgument:&self atIndex:2];    [m_touchMove retain];}


开始回调
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{    if (m_touchDown) {        [m_touchDown setArgument:&touch atIndex:3];        [m_touchDown setArgument:&event atIndex:4];        [m_touchDown invoke];    }    return YES;}


使用
[btn setTouchDownCallback:self sel:@selector(eventTouchBegin:touch:event:)];


回调函数

-(void) eventTouchBegin:(myButton*) sender touch:(UITouch*) touch event:(UIEvent*) event {   // TODO}




原创粉丝点击