zoukankan      html  css  js  c++  java
  • 自定义控键

    1、自定义View
     
    事件和响应者链
    //  ViewController.h
    //  自定义view
    //
    //  Created by tlh on 16/3/10.
    //  Copyright © 2016年 lamco. All rights reserved.
    //


    //事件和响应者链
    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController
    @property(strong,nonatomic)UILabel *lbltest;
    @property(strong,nonatomic)UIButton *btn;
    @property(strong,nonatomic)UIView *view1;
    @property(strong,nonatomic)UIView *view2;
    @end
     
    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
       
       
        self.lbltest=[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 100)];
        self.lbltest.backgroundColor=[UIColor grayColor];
        self.lbltest.text=@"test";
       
        [self.view addSubview:self.lbltest];
       
        self.btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
        self.btn.frame=CGRectMake(100, 100, 50, 50);
        [self.btn setTitle:@"TEST" forState:UIControlStateNormal];
        [self.btn addTarget:self action:@selector(Testbtn) forControlEvents:UIControlEventTouchUpInside];
        [self.lbltest addSubview:self.btn];
       
    //    是否与用户交互 label默认是不交互。yes。
        self.lbltest.userInteractionEnabled=YES;
       
       
        self.view1=[[UIView alloc]initWithFrame:CGRectMake(100, 350, 200, 200)];
        self.view1.backgroundColor=[UIColor redColor];
        self.view2=[[UIView alloc]initWithFrame:CGRectMake(50,50, 50, 50)];
        self.view2.backgroundColor=[UIColor greenColor];
        [self.view1 addSubview:self.view2];
        [self.view addSubview:self.view1];
    }
    -(void)Testbtn
    {
        NSLog(@"btn");
    }
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"begin");
       
    //    v1
        NSLog(@"%@",[self.view2 nextResponder]);
    //    view
            NSLog(@"%@",[[self.view2 nextResponder] nextResponder]);
    //    window  容器
            NSLog(@"%@",[[[self.view2 nextResponder] nextResponder] nextResponder]);
    //uiapplication 类
         NSLog(@"%@",[[[[self.view2 nextResponder] nextResponder] nextResponder] nextResponder]);
       
    //    Appdelegate  协议
        NSLog(@"%@",[[[[[self.view2 nextResponder] nextResponder] nextResponder] nextResponder] nextResponder]);
       
    //  null   再往下为空
       
    }
    -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"end");
    }


    -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"move");
    }
  • 相关阅读:
    Linux基础命令(二)
    Linux基础命令(一)
    安装Centos 7操作系统
    网络基础之网络协议
    操作系统简介
    计算机硬件知识
    VS快捷键
    VB.NET 编程元素支持更改总结
    VB.Net中确认退出对话框的实现
    VB定义变量
  • 原文地址:https://www.cnblogs.com/tianlianghong/p/5263659.html
Copyright © 2011-2022 走看看