zoukankan      html  css  js  c++  java
  • UIGestureRecognizer 手势想知道你点到了哪个控件吗,点这里

    给一连串的控件增加了UIGestureRecognizer 手势的时候 ,因为控件是动态增加的,点击时不知道如何确定自己点在哪个控件上。想取控件的属性值,取不到那就看这里。
    代码如下
    UIGestureRecognizer* Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTouch:)]; // 创建手势
    [myImage addGestureRecognizer:Tap];// 在图片上增加手势
    myImage.tag = 100;// 给图片增加一个唯一标识
    - (void)imageTouch:(UITapGestureRecognizer * )sender
    {
    NSLog(@"%@",sender.self.view);// 这个view 就是点击的那个控件
    }

    例子:

        //增加一行意见模版
        [[OAApplication shareApplication] getOpinionTemplate:^(id dictionary) {
            NSArray *temps = [dictionary objectForKey:@"rows"];
            sc1.contentSize = CGSizeMake(110*temps.count+10, 105);
            for (int i = 0; i < temps.count; i++) {
                NSDictionary  * dic  = [temps objectAtIndex:i];
                NSString *template = [dic objectForKey:@"context"];
                UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(110*i+10, 0, 95, sc1.frame.size.height)];
                textV.backgroundColor  =  [UIColor sepLineColor];
                textV.text =template;
                textV.editable = NO;
                textV.selectable = NO;
                [sc1 addSubview:textV];
                
                UITapGestureRecognizer *textVtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectTemp:)];
                [textV addGestureRecognizer:textVtap];
    
            }
            
            UIButton *addtemp = [[UIButton alloc]initWithFrame:CGRectMake(110*temps.count+10, 0, 100, sc1.frame.size.height)];
            [addtemp setImage:[UIImage imageNamed:@"xinjian"] forState:UIControlStateNormal];
            addtemp.backgroundColor = [UIColor sepLineColor];
            [sc1 addSubview:addtemp];
        }];



    //点击意见模版,选择意见

    - (void)selectTemp:(UITapGestureRecognizer *)sender{

        UITextView *textV = (UITextView *)sender.self.view;

        DCFLog(@"********%@ ",textV.text);

        _myOpinion = textV.text;

        _styleBopinion.text = textV.text;

    }

     

     

  • 相关阅读:
    要如何用[ZT]sendmessage來切換PageControl1 的TabSheet2呢
    Delphi 常用API 函数
    [ZT]如何得到其他程序的Richedit中的RTF数据
    转帖一篇关于DELPHI调试的文章AQTime
    讀取股票資料檔與指標計算方法之封裝
    GC的三代回收机制
    SQL语句的解析过程
    .Net 垃圾回收机制整理
    美国人吃了交通罚单怎么办?
    Ihttphandler,Ihttpmodule
  • 原文地址:https://www.cnblogs.com/OIMM/p/14297761.html
Copyright © 2011-2022 走看看