IPhone开发 IPad使用UIModalPresentationFormSheet时隐藏键盘

普通的做法resignFirstResponder在UIModalPresentationFormSheet的时候不起效 加上如下代码:


[passwordField resignFirstResponder]; 
@try { 
Class UIKeyboardImpl = NSClassFromString(@"UIKeyboardImpl");
  id activeInstance = [UIKeyboardImpl performSelector:@selector(activeInstance)]; [activeInstance performSelector:@selector(dismissKeyboard)]; 
}
@catch (NSException *exception) { 
NSLog(@"%@", exception); 

}


注意这个是jailbreak开发的代码,appstore慎用。

你可能感兴趣的:(短代码(代码片段))