• 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;

    }

     

     

  • 相关阅读:
    base64编码
    ios开发之指纹识别
    date
    php的学习
    mac下安装mysql遇到的无法连接的问题
    关于git上传文件过大报错的问题 remote: warning: Large files detected.
    安卓开发中Theme.AppCompat.Light的解决方法
    ubuntu操作系统中卸载mysql的安装与卸载
    重新格式化删除U盘隐藏分区与如何在LMT下安装非Ghost win7
    网易有道笔试2015-05-12
  • 原文地址:https://www.cnblogs.com/OIMM/p/14297761.html
Copyright © 2020-2023  润新知