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");
    }
  • 相关阅读:
    哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)
    ACM_X章求和(数学)
    goj 扫雷(dfs)
    Sereja and Brackets(括号匹配)
    NOIP模拟赛 迷路
    NOIP模拟赛three(3)
    NOIP模拟赛2(two)
    NOIP模拟赛1(one)
    czy的后宫5
    [BZOJ3436]小K的农场
  • 原文地址:https://www.cnblogs.com/tianlianghong/p/5263659.html
Copyright © 2011-2022 走看看