UIEvent UIResponder UI_04
2023-09-27 14:26:37 时间
PinchView *pinchView
= [[PinchView alloc]initWithFrame:CGRectMake(60, 184, 200, 200)];
pinchView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:pinchView];
//如果想让一个视图对象对触摸事件作出反应,需要在这个类中的.m文件中实现跟触摸相关一些方法
withEvent:(UIEvent *)event{
// self.backgroundColor = [UIColor randomColor];
self.center = CGPointMake(arc4random_uniform(220 - 100 + 1) + 100, arc4random_uniform(468 - 100 +1) +100);
//取出手指对像
UITouch *f = [touches anyObject];
//当前手指的 位置
CGPoint location = [f locationInView:self];
//之前手指位置
CGPoint previousLocation = [f previousLocationInView:self];
CGPoint center = self.center;
CGFloat dx = location.x - previousLocation.x;
CGFloat dy = location.y - previousLocation.y;
self.center = CGPointMake(center.x + dx, center.y +
UITouch *touch2 = [allTouchs lastObject];
//求出两个手指对象当前的位置
CGPoint firstTouch1 = [touch1 locationInView:self];
CGPoint secondTouch2 = [touch2 locationInView: self];
//求出当前两个手指的间距
CGFloat currentDistance = [self distanceFromeFirstPoint:firstTouch1 secondPoint:secondTouch2];
//求出之前两个手指的位置
CGPoint previousFirstPoint = [touch1 previousLocationInView:self];
CGPoint previousSecondPoint = [touch2 previousLocationInView:self];
//求出之前两个点的距离
CGFloat previousDistance = [self distanceFromeFirstPoint:previousFirstPoint secondPoint:previousSecondPoint];
= currentDistance / previousDistance;
//缩放视图,如果视图的大小发生变化时,而中心点的位置不发生变化,修改bounds就可以了
self.bounds = CGRectMake(0, 0, self.bounds.size.width * rate, self.bounds.size.height * rate);
}
}
//封装一个计算距离的方法(sqrt求开方)
- (CGFloat)distanceFromeFirstPoint : (CGPoint)firstPoint secondPoint : (CGPoint)secondPoint{
CGFloat dx = firstPoint.x - secondPoint.x;
CGFloat dy = firstPoint.y - secondPoint.y;
//当前两点距离
return sqrt(dx * dx + dy * dy);
1、 UIResponder 响应者类,继承自NSObject,它是一个响应者的基类,它提供了一些处理事件的方法
//什么是响应者(响应者对象):1.继承自UIResponder 2.能对ios事件中(触摸事件,晃动事件,远程事件)做出响应的对象就叫做响应者
响应者链:确定事件作用的对象时,UIAppcation --- UIAppcationDelegate--- window--- 视图控制器--- 视图控制器上的子视图
响应事件:(有大到小)视图控制器上的子视图--- 视图控制器--- window--- UIAppcationDelegate---UIAppcation 如果都不处理这个事件,事件就会被丢弃
ResponderView *redView = [[ResponderView alloc]initWithFrame:[UIScreenmainScreen].bounds];
redView.tag = 101;
redView.userInteractionEnabled = NO;
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
[redView release];
ResponderView *yellowView = [[ResponderView alloc]initWithFrame:CGRectMake(30, 360, 320, 284)];
yellowView.tag = 102;
//关闭用户的交互造成响应者链就到这个位置断开了,事件只能找他的上一级处理,如果上一级都不处理,此事件就不了了之了
yellowView.userInteractionEnabled = YES;
yellowView.backgroundColor = [UIColor yellowColor];
[redView addSubview:yellowView];
[yellowView release];
ResponderView *greenView = [[ResponderView alloc]initWithFrame:CGRectMake(20, 20, 280, 244)];
greenView.tag = 103;
greenView.backgroundColor = [UIColor greenColor];
[yellowView addSubview:greenView];
[greenView release];
ResponderView *blueView = [[ResponderView alloc]initWithFrame:CGRectMake(20, 20, 240, 204)];
blueView.tag = 104;
blueView.backgroundColor = [UIColor blueColor];
[greenView addSubview:blueView];
1、tableView的编辑的步骤: 1.让tableView处于编辑状态,(默认所有的cell都处于编辑状态,默认下的编辑样式是删除) 2.设置哪些cell可以编辑 3.设置编辑的样式(删除,插入)
历经百年风霜,苦经岁月沧桑。农大,一个中原沃土上生长起来的大树,它在用它那不倒的生命力展示着农大的顽强与坚持,而这份苍劲和顽强,却来自于每个农大人,来自于他们的梦想,来自于他们的坚持,来自于他们的努力。
自 WWDC 2015 推出和开源 Swift 2.0 后,大家对 Swift 的热情又一次高涨起来,在羡慕创业公司的朋友们大谈 Swift 新特性的同时,也有很多像我一样工作上依然需要坚守着 Objective-C 语言的开发者们。
pinchView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:pinchView];
//如果想让一个视图对象对触摸事件作出反应,需要在这个类中的.m文件中实现跟触摸相关一些方法
withEvent:(UIEvent *)event{
// self.backgroundColor = [UIColor randomColor];
self.center = CGPointMake(arc4random_uniform(220 - 100 + 1) + 100, arc4random_uniform(468 - 100 +1) +100);
//取出手指对像
UITouch *f = [touches anyObject];
//当前手指的 位置
CGPoint location = [f locationInView:self];
//之前手指位置
CGPoint previousLocation = [f previousLocationInView:self];
CGPoint center = self.center;
CGFloat dx = location.x - previousLocation.x;
CGFloat dy = location.y - previousLocation.y;
self.center = CGPointMake(center.x + dx, center.y +
UITouch *touch2 = [allTouchs lastObject];
//求出两个手指对象当前的位置
CGPoint firstTouch1 = [touch1 locationInView:self];
CGPoint secondTouch2 = [touch2 locationInView: self];
//求出当前两个手指的间距
CGFloat currentDistance = [self distanceFromeFirstPoint:firstTouch1 secondPoint:secondTouch2];
//求出之前两个手指的位置
CGPoint previousFirstPoint = [touch1 previousLocationInView:self];
CGPoint previousSecondPoint = [touch2 previousLocationInView:self];
//求出之前两个点的距离
CGFloat previousDistance = [self distanceFromeFirstPoint:previousFirstPoint secondPoint:previousSecondPoint];
= currentDistance / previousDistance;
//缩放视图,如果视图的大小发生变化时,而中心点的位置不发生变化,修改bounds就可以了
self.bounds = CGRectMake(0, 0, self.bounds.size.width * rate, self.bounds.size.height * rate);
}
}
//封装一个计算距离的方法(sqrt求开方)
- (CGFloat)distanceFromeFirstPoint : (CGPoint)firstPoint secondPoint : (CGPoint)secondPoint{
CGFloat dx = firstPoint.x - secondPoint.x;
CGFloat dy = firstPoint.y - secondPoint.y;
//当前两点距离
return sqrt(dx * dx + dy * dy);
1、 UIResponder 响应者类,继承自NSObject,它是一个响应者的基类,它提供了一些处理事件的方法
//什么是响应者(响应者对象):1.继承自UIResponder 2.能对ios事件中(触摸事件,晃动事件,远程事件)做出响应的对象就叫做响应者
响应者链:确定事件作用的对象时,UIAppcation --- UIAppcationDelegate--- window--- 视图控制器--- 视图控制器上的子视图
响应事件:(有大到小)视图控制器上的子视图--- 视图控制器--- window--- UIAppcationDelegate---UIAppcation 如果都不处理这个事件,事件就会被丢弃
ResponderView *redView = [[ResponderView alloc]initWithFrame:[UIScreenmainScreen].bounds];
redView.tag = 101;
redView.userInteractionEnabled = NO;
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
[redView release];
ResponderView *yellowView = [[ResponderView alloc]initWithFrame:CGRectMake(30, 360, 320, 284)];
yellowView.tag = 102;
//关闭用户的交互造成响应者链就到这个位置断开了,事件只能找他的上一级处理,如果上一级都不处理,此事件就不了了之了
yellowView.userInteractionEnabled = YES;
yellowView.backgroundColor = [UIColor yellowColor];
[redView addSubview:yellowView];
[yellowView release];
ResponderView *greenView = [[ResponderView alloc]initWithFrame:CGRectMake(20, 20, 280, 244)];
greenView.tag = 103;
greenView.backgroundColor = [UIColor greenColor];
[yellowView addSubview:greenView];
[greenView release];
ResponderView *blueView = [[ResponderView alloc]initWithFrame:CGRectMake(20, 20, 240, 204)];
blueView.tag = 104;
blueView.backgroundColor = [UIColor blueColor];
[greenView addSubview:blueView];
1、tableView的编辑的步骤: 1.让tableView处于编辑状态,(默认所有的cell都处于编辑状态,默认下的编辑样式是删除) 2.设置哪些cell可以编辑 3.设置编辑的样式(删除,插入)
历经百年风霜,苦经岁月沧桑。农大,一个中原沃土上生长起来的大树,它在用它那不倒的生命力展示着农大的顽强与坚持,而这份苍劲和顽强,却来自于每个农大人,来自于他们的梦想,来自于他们的坚持,来自于他们的努力。
自 WWDC 2015 推出和开源 Swift 2.0 后,大家对 Swift 的热情又一次高涨起来,在羡慕创业公司的朋友们大谈 Swift 新特性的同时,也有很多像我一样工作上依然需要坚守着 Objective-C 语言的开发者们。
相关文章
- Unity & 蓝湖 关于UI工作流优化的思考
- SSL & TLS 协议运行机制详解
- 【Java 线程 · 并发】LockSupport 线程控制 & Unsafe 核心类
- [RN] 07 - UI Component: TextInput, Image, Picker, ProgressBar & Viewpager
- 微信H5页面禁止转发分享功能&& 关闭微信内部浏览器
- 华为OJ 公共字串计算&&查找两个字符串a,b中的最长公共子串
- UIPassValue页面传值 UI_08(下)
- UILabel-UITextField-UIBotton UI_…
- 深度学习&机器学习资源汇总1
- winform正在使用dsoframer迅速"Unable to display the inactive document.Click here to reacitive the document."
- 常用js库和框架(vue&element ui与webpy)
- 从零开始玩转JMX(四)——Apache Commons Modeler & Dynamic MBean
- 我的Java开发学习之旅------>Java双重检查锁定及单例模式详解(转)