• 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
  • 相关阅读:
    以前给工大软件学院作得首页
    rinruby
    螃蟹为什么煮熟后会变红?
    关于R中利用apply、tapply、lapply、sapply、mapply、table
    hp laserjet 1020驱动 for windows
    关于睡觉巻起来姿势
    王强英語
    进程的前后台切换
    研究生=烟酒生
    计算矩阵乘法的网页工具
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13378988.html
Copyright © 2020-2023  润新知