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;

    }

     

     

  • 相关阅读:
    区块链
    git在IDEA中的使用
    hadoop linux 杂记
    idea java web 使用说明
    克隆虚拟机,解决网卡问题
    最小化CentOS6.7(64bit)---安装mysql5.5、jdk、tomcat
    爬虫学习笔记(1)--环境准备与正则表达式
    图论 BZOJ 3669 [Noi2014]魔法森林
    Manacher Ural 1297 Palindrome
    动态规划,贪心 APIO 2015 Sculptures
  • 原文地址:https://www.cnblogs.com/OIMM/p/14297761.html
Copyright © 2011-2022 走看看