- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 200, 200)]; textField.backgroundColor=[UIColor redColor]; [self.view addSubview:textField]; }//第一種收起鍵盤的方法-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES];}//第二種收起鍵盤的方法-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [[UIapplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];}//第三種收起鍵盤的方法-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [[[UIApplication sharedApplication] keyWindow] endEditing:YES];}
參考資料: 《iOS開發進階》 -唐巧
新聞熱點
疑難解答