我创建了 uitextfield 作为 uiimageview 的子视图 & textfield 和 uiimageview 都是滚动视图的子视图。编辑文本字段时隐藏键盘的方法是什么。这是我的代码,它不起作用。
{
img1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 1, 320, 60)];
img1.userInteractionEnabled=YES;
NSString *imgfilepath=[[NSBundle mainBundle]pathForResource:@"123" ofType:@"png"];
UIImage *imo=[[UIImage alloc]initWithContentsOfFile:imgfilepath];
[img1 setImage:imo];
UILabel *label1;
label1=[[UILabel alloc]init];
label1.frame=CGRectMake(60, 0, 250, 30);
label1.text=@"ENTER ANNUAL INCOME";
label1.textColor=[UIColor blackColor];
label1.font=[UIFont italicSystemFontOfSize:16.0f];
label1.backgroundColor=[UIColor clearColor];
[img1 addSubview:label1];
principal = [[UITextField alloc] initWithFrame:CGRectMake(85,30, 156, 40)];
principal.backgroundColor = [UIColor clearColor];
principal.clearButtonMode = UITextFieldViewModeWhileEditing;
principal.font = [UIFont systemFontOfSize:15.0f];
principal.placeholder=@"ENTER";
[principal setKeyboardType:UIKeyboardTypeNumberPad];
//principal.textAlignment=UITextAlignmentCenter;
[img1 addSubview:principal];
[img1 respondsToSelector:[principal resignFirstResponder]];
[scrollview addSubview:img1];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[principal resignFirstResponder];
}