iOS 弹出UIModalPresentationFormSheet模式
UIViewController*fbsheet = [[FeedbackSheet alloc] initWithNibName:@"FeedbackSheet"bundle:nil];
fbsheet.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:fbsheet animated:YES];
但是当在UItextview软盘弹出之后,点击其他区域使用下面代码软盘无法隐藏
方法一:
重写disablesAutomaticKeyboardDismissal即可,该api在iOS (4.3 andlater)
-(BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
方法二:
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar * topView =[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[topViewsetBarStyle:UIBarStyleBlack];
UIBarButtonItem *btnSpace = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:self action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"收起键盘"style:UIBarButtonItemStyleDone target:selfaction:@selector(dismissKeyBoard)];
[doneButtonsetWidth:80];
NSArray * buttonsArray =[NSArray arrayWithObjects:btnSpace,doneButton,nil];
[doneButton release];
[btnSpace release];
[topViewsetItems:buttonsArray];
[feedbackContentsetInputAccessoryView:topView];
}
-(IBAction)dismissKeyBoard
{
[feedbackContentresignFirstResponder];
}
方法三:
UINavigationController *nv =[[UINavigationController alloc]initWithRootViewController:searchVC];
nv.modalPresentationStyle = UIModalPresentationFormSheet;
[selfpresentModalViewController:nv animated:YES];
UINavigationController必须用Category的方法实现如下方法,才可以让键盘消失
@interface UINavigationController (DismissKeyboard)
- (BOOL)disablesAutomaticKeyboardDismissal;
@end
@implementation UINavigationController (DismissKeyboard)
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
方法四:此方法是能解决关闭键盘,可是苹果审核会拒绝使用该api
[textF resignFirstResponder];//没起到键盘收起的效果
@try {
Class UIKeyboardImpl =NSClassFromString(@"UIKeyboardImpl");
id activeInstance = [UIKeyboardImplperformSelector:@selector(activeInstance)];
[activeInstanceperformSelector:@selector(dismissKeyboard)];
}
@catch (NSException*exception) {
NSLog(@"%@", exception);
}
方法五:
//关闭键盘
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
如果一个view上好多输入框,为了关闭弹出的软键盘要遍历然后调用resignFirstResponder的吧?发现一个关键这个view上可能 打开的键盘很简单:[self.view endEditing:YES];
直接ok了。
方法六:
//关闭键盘
[[self findFirstResponderBeneathView:self] resignFirstResponder];
[[self findFirstResponderBeneathView:self] becomeFirstResponder];//打开键盘
-(UIView*)findFirstResponderBeneathView:(UIView*)view
{
// Search recursivelyfor first responder
for ( UIView *childViewin view.subviews ) {
if ( [childViewrespondsToSelector:@selector(isFirstResponder)]&& [childView isFirstResponder])
returnchildView;
UIView *result = [selffindFirstResponderBeneathView:childView];
if ( result )
returnresult;
}
return nil;
}