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
  • 相关阅读:
    [Clr via C#读书笔记]Cp4类型基础
    [Clr via C#读书笔记]Cp3共享程序集和强命名程
    [Clr via C#读书笔记]Cp2生成打包部署和管理应用程序和类型
    [Clr via C#读书笔记]Cp1CLR执行模型
    试用Markdown来写东西
    字符编码的总结
    常去的网站
    Click Once使用总结
    【LevelDB源码阅读】Slice
    【程序员面试金典】面试题 01.05. 一次编辑
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13378988.html
Copyright © 2011-2022 走看看