Sam*_*erg 10 keyboard ios ios7
我想要一个带有非透明键盘的键盘 - 我无法使用任何支持的UIKeyboardTypes.还有另一种方法吗?
我想我可以用键盘上的背景视图覆盖我想要的颜色 - 是否有一种很好的方法可以与键盘节目动画同步动画该背景视图?
当使用 iOS 7 的 Base SDK 在 Xcode 5 中编译应用程序时,iOS7 中的键盘是半透明的。
如果您在 Xcode 4.6.x 上构建应用程序,您将像以前一样拥有非半透明的键盘。
(我知道这是一个糟糕的修复,但尽管如此,我想我会建议它)
无论如何,您也可以尝试使用默认键盘通知:
UIKeyboardWillShowNotificationUIKeyboardWillHideNotification应该是这样的:
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
Run Code Online (Sandbox Code Playgroud)
-(void)keyboardWillShow:(NSNotification *)note
{
/*
Would have used:
CGRect rectStart = [note.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect rectEnd = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
Reason for not using:
The above two keys are not being used although, ideally, they should have been
since they seem to be buggy when app is in landscape mode
Resolution:
Using the deprecated UIKeyboardBoundsUserInfoKey since it works more efficiently
*/
CGRect rectStart_PROPER = [note.userInfo[UIKeyboardBoundsUserInfoKey] CGRectValue];
rectStart_PROPER.origin.y = self.view.frame.size.height;
UIView *vwUnderlay = [self.view viewWithTag:8080];
if (vwUnderlay) {
[vwUnderlay removeFromSuperview];
}
vwUnderlay = [[UIView alloc] init];
[vwUnderlay setFrame:rectStart_PROPER];
[vwUnderlay setBackgroundColor:[UIColor orangeColor]];
[vwUnderlay setTag:8080];
[self.view addSubview:vwUnderlay];
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]
delay:0
options:[note.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16
animations:^{
[vwUnderlay setFrame:CGRectOffset(vwUnderlay.frame, 0, -vwUnderlay.frame.size.height)];
}
completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
-(void)keyboardWillHide:(NSNotification *)note
{
UIView *vwUnderlay = [self.view viewWithTag:8080];
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]
delay:0
options:[note.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16
animations:^{
[vwUnderlay setFrame:CGRectOffset(vwUnderlay.frame, 0, vwUnderlay.frame.size.height)];
}
completion:^(BOOL finished){
[vwUnderlay removeFromSuperview];
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2213 次 |
| 最近记录: |