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