Skip to content

Instantly share code, notes, and snippets.

@monjer
Last active December 16, 2015 11:59
Show Gist options
  • Select an option

  • Save monjer/5431732 to your computer and use it in GitHub Desktop.

Select an option

Save monjer/5431732 to your computer and use it in GitHub Desktop.
获取app中firstResponder对象
//
// 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
//
// 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