Last active
December 16, 2015 11:59
-
-
Save monjer/5431732 to your computer and use it in GitHub Desktop.
获取app中firstResponder对象
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIResponder+FirstResponder.h | |
| // | |
| // Created by manjun.han on 13-4-18. | |
| // Copyright (c) 2013年 com.hmj. All rights reserved. | |
| // | |
| #import <UIKit/UIKit.h> | |
| @interface UIResponder (FirstResponder) | |
| -(void)setYourselfToGlobalFirstResponder ; | |
| @property (nonatomic , weak) id currentFirstResponder ; | |
| + (id)currentFirstResponder ; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIResponder+FirstResponder.m | |
| // | |
| // Created by manjun.han on 13-4-18. | |
| // Copyright (c) 2013年 com.hmj. All rights reserved. | |
| // | |
| #import "UIResponder+FirstResponder.h" | |
| static __weak id currentFirstResponder; | |
| @implementation UIResponder (FirstResponder) | |
| @dynamic currentFirstResponder ; | |
| -(void)setYourselfToGlobalFirstResponder | |
| { | |
| currentFirstResponder = self; | |
| } | |
| - (id)currentFirstResponder | |
| { | |
| return [UIResponder currentFirstResponder]; | |
| } | |
| + (id)currentFirstResponder | |
| { | |
| currentFirstResponder = nil; | |
| // 同步消息 | |
| [[UIApplication sharedApplication] sendAction:@selector(setYourselfToGlobalFirstResponder) | |
| to:nil | |
| from:nil | |
| forEvent:nil]; | |
| return currentFirstResponder; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment