点击空白处回收键盘

一: 效果图

效果描述:点击空白处快速回收键盘

     

二: 工程图

三:代码区

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (retain, nonatomic) UIWindow *window;


@end

AppDelegate.m

#import "AppDelegate.h"
#import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc
{
    self.window = nil;
    
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    RootViewController *rootView = [[RootViewController alloc] init];
    
    UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:rootView];
    
    self.window.rootViewController = navigationVC;
    
    [rootView release];
    
    [navigationVC release];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@property (nonatomic , retain) UITextField *text1;

@property (nonatomic , retain) UITextField *text2;

@property (nonatomic , retain) UITextField *text3;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self showText];
}

#pragma mark - 创建控件
- (void)showText {
    
    self.text1 = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 260, 40)];
    
    _text1.borderStyle = 2;
    
    self.text2 = [[UITextField alloc] initWithFrame:CGRectMake(30, 160, 260, 40)];
    
    _text2.borderStyle = 2;
    
    self.text3 = [[UITextField alloc] initWithFrame:CGRectMake(30, 220, 260, 40)];
    
    _text3.borderStyle = 2;
    
    [self.view addSubview:_text1];
    
    [self.view addSubview:_text2];
    
    [self.view addSubview:_text3];
    
    [_text1 release];
    
    [_text2 release];
    
    [_text3 release];
}

#pragma mark - 回收键盘的核心代码

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    [self.text1 resignFirstResponder];
    
    [self.text2 resignFirstResponder];
    
    [self.text3 resignFirstResponder];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

转载于:https://www.cnblogs.com/li625317534/p/5051487.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值