首页 > 其他 > 详细

UI基础 事件

时间:2020-07-26 10:54:39      阅读:68      评论:0      收藏:0      [点我收藏+]

 

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

 

UI基础 事件

原文:https://www.cnblogs.com/zhangqing979797/p/13378988.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!