UI-事件处理
来源:互联网 发布:windows查看内存型号 编辑:程序博客网 时间:2024/05/22 06:26
补充:按钮字符串替换
// 按钮在 显示和隐藏两个字符串之间替换 点击一下 替换一下- (void)buttonAction:(UIButton *)sender { #pragma 方法一:// if (sender.selected) { // selected 的默认值是NO 第一次点击无效果// [sender setTitle:@"隐藏" forState:UIControlStateNormal];//// sender.selected = NO;// }else {// [sender setTitle:@"显示" forState:UIControlStateNormal];//// sender.selected = YES;// }// sender.selected = !sender.selected; // BOOL值可以取非 #pragma 方法二:// sender.selected = !sender.selected; // BOOL值可以取非// sender.selected ? [sender setTitle:@"隐藏" forState:UIControlStateNormal] : [sender setTitle:@"显示" forState:UIControlStateNormal]; #pragma 方法三: sender.selected = !sender.selected; // BOOL值可以取非 [sender setTitle:sender.selected?@"隐藏":@"显示" forState:UIControlStateNormal]; }
UIViewController是MVC设计模式的核心。MVC是一个框架级的设计模式。
M是Model主要⽤用于建⽴数据模型(即数据的结构)
V是View,我们能看到的所有控件都view,view主要的功能是展示数据。
C是控制器,主要是控制M和V的通信。
View:在自定义视图中创建控件,初始化控件,设置一些基本的属性。
Controller:在控制器中写一些视图的触发事件
1. 触摸事件:
#pragma Touch--触摸的时候开始发送消息 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 集合里存储对象---NSSet NSLog(@"触摸------开始"); } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"over"); } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint point1 = [touch locationInView:self.rootV.touchView]; CGPoint point2 = [touch previousLocationInView:self.rootV.touchView]; CGPoint center = self.rootV.touchView.center; CGFloat x = point1.x - point2.x; CGFloat y = point1.y - point2.y; // 判断范围......最大的横纵坐标值 CGFloat MaxX = [UIScreen mainScreen].bounds.size.width; CGFloat MaxY = [UIScreen mainScreen].bounds.size.height; CGFloat radius = self.rootV.touchView.layer.cornerRadius;// 半径 // 视图的四个边界值 CGFloat leftX = center.x + x - radius; CGFloat rightX = center.x + x + radius; CGFloat topY = center.y + y - radius; CGFloat downY = center.y + y + radius; if (rightX <= MaxX && leftX >= 0 ) { if (topY >= 0 && downY <= MaxY) { self.rootV.touchView.center = CGPointMake(center.x + x, center.y + y); } } } -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { }
userInteractionEnabled属性:是控制是否阻断响应的属性(BOOL)
UITouch的两个方法:
- (CGPoint)locationInView:(UIView *)view;----返回当前触摸点的坐标
- (CGPoint)previousLocationInView:(UIView *)view;----返回当前的触摸点之前一个点的坐标(看API文档 有解释)
2. 响应者链:
响应事件查询顺序:UIApplication-->window-->viewController-->view-->所有的子视图
事件处理顺序:被点击的子视图-->view-->viewController-->window-->UIApplication-->事件作废
3.控制晃动(运动事件)
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ //检测到摇动 NSLog(@"这个是检测有没有摇晃的 反正你也看不到 →_→ →_→"); }- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{ NSLog(@"摇晃结束~ ~ ~"); if (event.subtype == UIEventSubtypeMotionShake) { UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"TEST" message:@"机智如我" delegate:nil cancelButtonTitle:@"我本来就机智" otherButtonTitles:@"我确定我很机智",nil]; [alertView show]; }}- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{ //摇动取消}
4. 屏幕旋转:
//获得当前方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return toInterfaceOrientation == UIDeviceOrientationPortrait; } //开启旋转 - (BOOL)shouldAutorotate { return YES; }
0 0
- Android UI事件处理
- Android UI事件处理
- Android UI事件处理
- Android UI事件处理
- Android UI事件处理
- Android UI事件处理
- UI 事件处理UITouch
- UI开发----事件处理
- UI - 事件处理UITouch
- UI-事件处理
- UI基础-事件处理
- UI事件处理:手势处理
- android ui事件处理分析
- Android UI事件处理[isInTouchMode()]
- android的UI事件处理
- UI笔记_事件处理
- UI控件 - 事件处理
- UI课程04 事件处理
- OC学习NSArray与NSMutableArray数组
- Android Studio使用教程-菜单(Edit)
- 搜索引擎
- 状态模式的具体实现 情景二
- sticklistview
- UI-事件处理
- GDB工具使用教程_函数调用栈(call stack)探密
- Android:带边框的,等比缩放的,铺满控件的ImageView
- 怎样利用模板拼接字符串
- i.MX 6Q开发环境配置
- 画虚线需要设置android:layerType="software",否则无效
- Swift之 ? 和 !
- Codevs P1652 淘汰赛制
- 序列化生成XML文件以及Pull解析