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]];
}    

 

 
posted @ 2015-09-23 11:46  lisen_李森  阅读(2600)  评论(0编辑  收藏  举报