UIKit 框架之UIResponder
前面博客有讲触摸事件提过响应事件和响应者链,而管理响应者链的正是UIResponder。
一、代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"window:%@",[self.window nextResponder]);
NSLog(@"AppDelegate: %@",[self nextResponder]);
return YES;
}
//
// ViewController.m
// UIResponder
//
// Created by cyw on 15-5-16.
// Copyright (c) 2015年 cyw. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITextFieldDelegate>
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *textField=[[UITextField alloc]init];
textField.frame=CGRectMake(100, 100, 100, 40);
textField.borderStyle=UITextBorderStyleLine;
textField.backgroundColor=[UIColor redColor];
textField.delegate=self;
textField.tag=10001;
BOOL canBecomeFirstResponder=[textField canBecomeFirstResponder ];
BOOL canResignFirstResponder=[textField canResignFirstResponder];
NSLog(@"%d %d",canBecomeFirstResponder,canResignFirstResponder);
[textField becomeFirstResponder];
[self.view addSubview:textField];
UITextField *textField1=[[UITextField alloc]init];
textField1.frame=CGRectMake(100, 200, 100, 40);
textField1.borderStyle=UITextBorderStyleLine;
textField1.backgroundColor=[UIColor redColor];
textField1.delegate=self;
textField1.tag=10002;
[self.view addSubview:textField1];
UIResponder *responder1= [textField nextResponder];
UIResponder *responder2=[self nextResponder];
UIResponder *responder3=[self.view nextResponder];
NSLog(@"textField:%@\nViewController:%@\nself.view:%@",responder1,responder2,responder3);
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
BOOL isFirstResponder= [textField isFirstResponder];
NSLog(@"textField%d isFirstResponder %d:",textField.tag,isFirstResponder);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
二、结果
2015-05-17 00:30:02.427 UIResponder[1132:60b] window:<UIApplication: 0x8d71b80> 2015-05-17 00:30:02.437 UIResponder[1132:60b] AppDelegate: (null) 2015-05-17 00:30:02.446 UIResponder[1132:60b] 1 1 2015-05-17 00:30:02.449 UIResponder[1132:60b] textField:<UIView: 0x8e742d0; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0x8e739e0>> ViewController:(null) self.view:<ViewController: 0x8c9b8c0> 2015-05-17 00:30:02.463 UIResponder[1132:60b] textField10001 isFirstResponder 1:
三、由上面的输出结果有一点比较纳闷,为什么ViewController返回的是NULL?我想了半天也没想到什么原因,也请高手给指点一下
四、其实UIResponder不仅仅只有这些,具体可以参考:http://southpeak.github.io/blog/2015/03/07/uiresponder/?utm_source=tuicool
UIKit 框架之UIResponder的更多相关文章
- UIKit框架使用总结--看看你掌握了多少
一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...
- Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)
原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- iOS学习32之UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 基础框架Fundation和UIkit框架的定义和使用
Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...
- iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。
转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架
Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...
- UIKit 框架之UIView二
下面这些都是UIView一些基本的东西,具体的可以参考UIKit 框架之UIView一博客 一.自定义一个View // // MyView.m // UIView // // Created by ...
随机推荐
- cpld fpga 区别
cpld fpga 区别 系统的比较,与大家共享: 尽管FPGA和CPLD都是可编程ASIC器件,有很多共同特点,但由于CPLD和FPGA结构上的差异,具有各自的特点: ①CPLD更适合完成各种算法和 ...
- AreaHttpControllerSelector 对 Web Api 实现 Area 路由控制
结合此文章:http://www.cnblogs.com/wuhuacong/p/5828038.html using System; using System.Collections.Concurr ...
- 【转】PowerDesigner删除外键关系,而不删除外键列
原文:https://blog.csdn.net/tomsyc/article/details/6075530 PowerDesigner中配置外键关系时,如果要删除配置的外键关系,默认设置会一同删除 ...
- Android------------------的快捷键的使用
https://www.cnblogs.com/shidian/p/6937630.html
- 【文文殿下】P3740 [HAOI2014]贴海报
题解 一开始想到离散化,然后暴力模拟.但是存在一种hack数据: [5,7] [1,5] [7,9] 这样会错误的认为第一个区间被覆盖了(因为两个端点被覆盖).所以我们设置一个玄学调参系数,在一个区间 ...
- react中组件的渲染
1.封装props对象 2.调用组件函数,得到返回的react元素 3.ReactDom把React元素转成真实的DOM元素并且插入到目标容器内部
- raspberry pi wifi
vim /etc/network/interfaces 修改 wpa-ssid 和 wpa-psk
- [Element-UI] 使用Element-UI的DateTimePicker组件报错:Cannot read property 'getHours' of undefined
使用Element-UI组件的DateTimePicker,如下: <template> <div class="block"> <span clas ...
- webApp在各大Android市场上的发布
本来打算每个月都写上一篇博客的,可是计划永远赶不上变化,不过这其中也有自己的懒惰,果然过年让整个人懈怠了不少.年后一直在赶项目以致于到今天才动手写这篇文章. 这一篇主要写点在公司的要求下发布的webA ...
- ping端口是否开放(windows,macos,linux)
windows中ping端口:tcping命令 1. tcping 非自带命令,首先安装tcping命令,也可以去官网:http://www.elifulkerson.com/projects/tcp ...