• UIControl


    前言

    • UIControl 从字面翻译成为控制器,可以触发事件,达到和用户进行交互。

    1、UIControl 的创建

    // 实例化 UIControl 对象
    UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2 - 100, 100, 200, 100)];
    
    control.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:control];
    
    // 添加/删除触发事件
    /*
    - (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
    - (void)removeTarget:(nullable id)target action:(nullable SEL)action forControlEvents:(UIControlEvents)controlEvents;
    
    (id)target:                        响应对象,就是触发了 control 的某个事件后响应谁的方法
    (SEL)action:                       触发某个事件后响应 target 的哪个方法
    (UIControlEvents)controlEvents:    触发 control 的哪个事件
    
    UIControlEventTouchDown              // 按下
    UIControlEventTouchDownRepeat        // 双击,连续按下2次
    UIControlEventTouchDragInside        // 内部拖动,不松手就触发事件,一直触发
    UIControlEventTouchDragOutside       // 向外拖出,不松手就触发事件,一直触发
    UIControlEventTouchDragEnter
    UIControlEventTouchDragExit          // 向外拖出,不松手就触发事件,只触发一次
    UIControlEventTouchUpInside          // 单击
    UIControlEventTouchUpOutside         // 向外拖出,松手后触发事件
    UIControlEventTouchCancel
    
    UIControlEventValueChanged           // 数值改变,sliders, etc.
    
    UIControlEventEditingDidBegin        // 开始编辑,UITextField
    UIControlEventEditingChanged         // 编辑中
    UIControlEventEditingDidEnd          // 结束编辑
    UIControlEventEditingDidEndOnExit    // 结束编辑,'return key' ending editing
    
    UIControlEventAllTouchEvents         // 所有事件,for touch events
    UIControlEventAllEditingEvents       // 所有编辑事件,for UITextField
    UIControlEventApplicationReserved    // range available for application use
    UIControlEventSystemReserved         // range reserved for internal framework use
    UIControlEventAllEvents
    */
    
    // 添加触发事件
    [control addTarget:self action:@selector(controlClick:) forControlEvents:UIControlEventTouchUpInside];
    
    // 一个控件可以添加多个事件
    [control addTarget:self action:@selector(controlClickOther:) forControlEvents:UIControlEventTouchDragOutside];
    
    // 删除添加的事件
    [control removeTarget:self action:@selector(controlClickOther:) forControlEvents:UIControlEventTouchDragOutside];
    

    2、自定义点击触发事件处理

    // 控件触发事件处理,一般响应方法都会有一个参数,没有也可以,该参数一般是触发的对象
    - (void)controlClick: (UIControl *)control {
    
    }
    
    - (void)controlClickOther: (UIControl *)control {
    
    }
    
  • 相关阅读:
    Distinctive Image Features from ScaleInvariant
    Natural Language Toolkit
    Regression analysis
    泌尿系统 Excretory system
    file_get_contents preg_match php nameisboy
    wWAITING
    instructionset architecture Processor Architecture
    improve performance whilemaintaining the functionality of a simpler and more abstract model design of processor hardware
    cluster analysis in data mining
    Maximum Likelihood
  • 原文地址:https://www.cnblogs.com/CH520/p/9413475.html
Copyright © 2020-2023  润新知