码迷,mamicode.com
首页 > 其他好文 > 详细

点击空白处回收键盘

时间:2015-12-16 17:18:02      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

一: 效果图

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

技术分享    技术分享 

二: 工程图

技术分享

三:代码区

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

 

点击空白处回收键盘

标签:

原文地址:http://www.cnblogs.com/li625317534/p/5051487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!