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

时间: 2024-08-25 08:32:48

UIKit 框架之UIResponder的相关文章

UIKit框架各个类的简介

1.UIAcceleration: 被叫做加速事件的一个UIAcceleration类的实例是用来代表即时的三维加速数据.为了接收重力加速度,要注册一个应用应用程序作为一个共享UIAccelerater对象的委托对象(参考UIAcceleromete类). 2. UIAccelerater: UIAccelerater类可以让你的寄存器接收到从板载硬件上得到的加速相关数据.当设备移动时,它的硬件能够报告沿主线在三维空间中的线性加速度变化.你可以利用这些数据来检测器件的电流方向和该方向的瞬时变化.

iOS UIKit框架

1. 简介: UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面( UI )接口.应用程序对象.事件控制.绘图模型.窗口.视图和用于控制触摸屏等的接口.(PS1: 可以认为是操纵界面的一个API库)(PS2: UIKit框架是用在iOS平台上与之对应的是MAC OS X上的Application Kit,二者是姐妹框架,作用和目的没啥太大区别(我没有说实现目的的过程也一样),表混淆了) 2. 框架的入口: #import <UIKit/UIKit.h>

iOS UIKit 框架 346 篇文档分类整理 - 预告

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 当前正在进行的是 "iOS Foundation 框架 224 篇相关文档分类整理",量很大,但会根据实际开发中的使用频繁程序

UIKit框架(2)框架简介

UIKit框架 什么是框架? 简单来说,就是其他攻城狮开发完成的代码,包括库文件.头文件等,这些文件中的API我们可以拿过来使用 UIKit框架是干什么的? 提供创建基于触摸用户界面的类 包括:屏幕上的绘制机制.捕捉事件.管理组织复杂的UI元素 UIKit中最重要的两个类? 1)UIView:所有可以看到的组件/控件/视图的父类 如:UIButton按钮.UILabel标签.UITextField输入框.UIImageView图片视图等 2)UIViewController:所有控制器的父类,负

UIKit框架使用总结--看看你掌握了多少

一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIScrollView.UITableView.UITableViewCell.UICollectionView.UICollectionViewCell.UITextView. UIViewController 二.偶尔使用,或者说不是每次都要敲出来的 1.功能专用 UIPickerView(数据选择

UIKit框架之UIButton详解

UIKit框架是iPhone应用程序开发中最基本的框架,也是用得最多.最重要的框架,今天要和大家分享的就是UIKit中的UIButton相关知识,一起来看看吧. 1.实例化: 1.1.init方式: 1 UIButton *button = [[UIButton alloc] initWithFrame:rect]; 1.2.类方法方式: 1 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 其中按钮类型枚

UIKit框架

在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应用程序对象.事件控制.绘图模型.窗口.视图和用于控制触摸屏等的接口. 二.框架的入口 #import <UIKit/UIKit.h> 三.框架图:

iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage风格 目录[-] UIDynamicAnimator UIAttachmentBehavior(吸附) UIPushBehavior(推动) UIGravityBehavior(重力) UICollisionBehavior(碰撞) UISnapBehavior(捕捉) UICollectionVi

cocoa的UIKit框架

在cocoa中有许多框架,其中最基本的也是最常用的就是Foundation框架和UIKit框架, Foudation框架是oc的基础框架,和界面无关. UIKit框架是与界面相关的基础框架.下面是UIKit框架的类组织架构图: 框架类组织架构图: