zoukankan      html  css  js  c++  java
  • UI基础 事件

    root.m

    #import "RootViewController.h"
    #import "MyView.h"
    @interface RootViewController ()
    {
        UITextField *tf;
        
    }
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        tf = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 60)];
        tf.backgroundColor=[UIColor redColor];
        [self.view addSubview:tf];
        
        MyView *view=[[MyView alloc]initWithFrame:CGRectMake(20, 300, 270, 200)];
        view.backgroundColor=[UIColor grayColor];
        // 关闭用户交互
        
        view.userInteractionEnabled=NO;
        
        [self.view addSubview:view];
        
        
        
    
    }
    
    // 触摸屏幕触发的方法
    -(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"触发控制器开始");
        
    }
    
    -(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        NSLog(@"取消控制器触摸");
        
    }
    -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"触摸控制器结束");
    }
    
    -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"移动控制器");
        
    }
    
    
    @end

    MyView.m

    #import "MyView.h"
    
    @implementation MyView
    //若注释掉 则会有控制器方法代替 一次传递
    // 触摸屏幕触发的方法
    -(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"触发view开始");
    
    }
    
    -(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        NSLog(@"取消view触摸");
    
    }
    -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"触摸view结束");
    }
    
    -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"移动view");
    
    }
    
    @end
  • 相关阅读:
    Collection LinkedList
    java 浅拷贝和深拷贝
    Collection ArrayList
    Java 集合
    Activity、Fragment、Service、View生命周期
    Android 事件分发机制
    retrofit2.0
    Android 知识图谱
    设计模式-代理模式
    多线程-lock
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13378988.html
Copyright © 2011-2022 走看看