在我的应用程序中,我有这样的东西:
- (IBAction)backgroundTouch:(id)sender
{
[businessDescription resignFirstResponder];
[self.view endEditing:YES];
}
我不确定我使用的两行中哪一个更好,所以我同时使用:) 它在突出显示文本区域并且用户按下背景时起作用。
但用户并不总是按背景,有时会按其他页面元素,例如他们试图填写的下一个元素。
在我的屏幕截图中,我在文本区域下方有下一个元素,当我点击那里时,键盘不会被隐藏。当用户单击各种页面元素以及文本区域碰巧没有突出显示时,谁能帮我隐藏键盘?
这是我的 .h 文件:
@interface PlanBusinessController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *businessDescription;
- (IBAction)submitBusiness:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *buttonProperty;
@property (weak, nonatomic) IBOutlet UITextField *personName;
@property (weak, nonatomic) IBOutlet UITextField *personEmail;
@property (weak, nonatomic)
IBOutlet UISwitch *privacy;
@property (weak, nonatomic) IBOutlet UISwitch *wantHelp;
- (IBAction)helpToggle:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet
UIButton *test;
@结尾
这是我的 .m 声明:
#import "PlanBusinessController.h"
@interface PlanBusinessController ()
@end
@implementation PlanBusinessController
@synthesize nameLabel;
@synthesize emailLabel;
@synthesize businessDescription;
@synthesize buttonProperty;
@synthesize personName;
@synthesize personEmail;
@synthesize privacy;
@synthesize wantHelp;
@synthesize test;
-(void)touchesBegan:(NSSet*)touches
{
UITouch *touch=[touches anyObject];
UIView *view=touch.view;
if (![view isEqual:businessDescription])
{
//[businessDescription resignFirstReponder];
}
}
- (IBAction)backgroundTouch:(id)sender
{
[businessDescription resignFirstResponder];
[self.view endEditing:YES];
}
谢谢!