弹出UIModalPresentationFormSheet模式
效果如下:
但是当在UItextview软盘弹出之后,点击其他区域使用下面代码软盘无法隐藏
进查询资料之后发现重写disablesAutomaticKeyboardDismissal即可,该api在iOS (4.3 and later)
还有一种方式就是通过在键盘上添加toolbar,也是一种比较简易的操作
效果如下:
参考资料: http://stackoverflow.com/questions/3019709/modal-dialog-does-not-dismiss-keyboard
- - (IBAction)buttonPressed:(id)sender
- {
- NSLog(@"Show feedback view now!");
- UIViewController *fbsheet = [[FeedbackSheet alloc] initWithNibName:@"FeedbackSheet" bundle:nil];
- fbsheet.modalPresentationStyle = UIModalPresentationFormSheet;
- [self presentModalViewController:fbsheet animated:YES];
- [fbsheet release];
- }
效果如下:
但是当在UItextview软盘弹出之后,点击其他区域使用下面代码软盘无法隐藏
- [feedbackContent resignFirstResponder];
进查询资料之后发现重写disablesAutomaticKeyboardDismissal即可,该api在iOS (4.3 and later)
- -(BOOL)disablesAutomaticKeyboardDismissal
- {
- return NO;
- }
还有一种方式就是通过在键盘上添加toolbar,也是一种比较简易的操作
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
- [topView setBarStyle:UIBarStyleBlack];
- UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
- UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithTitle:@"收起键盘" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
- [doneButton setWidth:80];
- NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace,doneButton,nil];
- [doneButton release];
- [btnSpace release];
- [topView setItems:buttonsArray];
- [feedbackContent setInputAccessoryView:topView];
- }
- -(IBAction)dismissKeyBoard
- {
- [feedbackContent resignFirstResponder];
- }
效果如下:
参考资料: http://stackoverflow.com/questions/3019709/modal-dialog-does-not-dismiss-keyboard