在我的应用程序中我有这样的东西:
- (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;
@end
这是我的 .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];
}
Thanks!