UITapGestureRecognizer 手势传值


- (void)setImageArray:(NSArray *)imageArray
{
    self.count = count;
    
    // 1.添加图片到scrollView中
    for (int i = 0; i < count; i++) {
        
        UIImageView *imageView = [[UIImageView alloc] init];
        
        imageView.tag = i;    // 传值
        
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toSafar:)];
        
        [imageView addGestureRecognizer:singleTap1];
    }
}

- (void)toSafar:(id)sender
{
    UITapGestureRecognizer *tap = (UITapGestureRecognizer *)sender;
    
    int tag = tap.view.tag; // 广告标示
    
    NSLog(@"tap.view.tag: %ld", (long)tap.view.tag);
    
    GBidModel * idModel = self.imageArray[tag];
    
    NSString *urlStr = idModel.pic_link;    // 相应的链接地址
    
    // 用浏览器打开
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlStr]];
}    

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM