将参数传递给方法 - UIPanGestureRecognizer

时间:2015-04-20 04:38:43

标签: ios objective-c

我想将UIPanGestureRecognizer参数从onCViewPanned方法传递给showFollowing

我试图通过UIGestureRecognizerStateBegan但是,它没有接受它。我该如何解决这个问题?

-(void) showFollowing{
    [self onCViewPanned: ??????];
}

- (void)onCViewPanned:(UIPanGestureRecognizer*)gesture {



    // do something

}

1 个答案:

答案 0 :(得分:2)

您可以像这样创建自定义UIPanGestureRecognizer

// MYPanGestureRecognizer.h

@interface MYPanGestureRecognizer : UIPanGestureRecognizer

@property (nonatomic, strong) NSString *data;

@end


// MYPanGestureRecognizer.m

@implementation MYPanGestureRecognizer

@end

// =================   
...

MYPanGestureRecognizer *panObj = [[MYPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];

panObj.datas = @"Hello";



// ====================
-(void)panDetected:(UIPanGestureRecognizer *)panRecognizer {

MYPanGestureRecognizer *pan = (MYPanGestureRecognizer *)panRecognizer;

NSLog(@"data : %@", pan.data);
}

希望它能帮到你......