我有2个视图:带标签1的视图和带标签2的视图。 每个视图都有两个手势识别器。
CGRect tempRect=CGRectMake(0, 0, 100, 100);
for (int i=1; i<=2; i++) {
UIView *tempView=[[UIView alloc] initWithFrame:tempRect];
UIImageView *tempImageView=[[UIImageView alloc]initWithFrame:tempRect];
tempImageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@%d%@",@"image_",i,@".png"]];
UISwipeGestureRecognizer *tempRecognizer = [[UISwipeGestureRecognizer alloc] init];
[tempRecognizer performSelector:@selector(SwipeRight:) withObject:[NSNumber numberWithInt:i]];
[tempRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[tempView addGestureRecognizer:tempRecognizer];
[tempView addSubview:tempImageView];
tempView.tag=i;
[self.view addSubview:tempView];
}
我有一个方法:SwipeRight管理滑动....
-(void)SwipeRight:(NSNumber*)MyTag{
int MyProgr = [MyTag intValue];
}
传递代码的正确方法是什么? 我的代码出错了:
[UISwipeGestureRecognizer SwipeRight:]: unrecognized selector sent to instance...
答案 0 :(得分:1)
在
之前设置视图标记[tempView setTag:i];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(callYourMethod:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[tempView addGestureRecognizer:swipeRight];
- (void)callYourMethod:(UISwipeGestureRecognizer *)recognizer
{
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
int tagValue = recognizer.view.tag;
NSLog(@"Down");
}
}
答案 1 :(得分:0)
请尝试使用此
-(void) SwipeRight:(UISwipeGestureRecognizer *)recognizer
{
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
int tag = recognizer.view.tag;
}
}