Dav*_*ave 3 objective-c uitoolbar uiview uikeyboard uisplitviewcontroller
这是一个非常新秀的问题.我在底部有一个UIToolBar,当显示UIKeyBoard时,它应该用键盘上下动画.我在UIKeyBoard Notifications的帮助下完成了这项工作.我们正在讨论的视图已启用拆分视图.当设备方向是横向时,两个视图都显示为[希望有意义].
当显示键盘时,我这样做
CGSize keyBoardSize = [[notificationInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
CGRect toolbarFrame= [BottomToolBar frame];
toolbarFrame.origin.y -= keyBoardSize.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
BottomToolBar .frame = viewFrame;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
当键盘是hiiden我这样做
toolbarFrame.origin.y += keyBoardSize.height;
Run Code Online (Sandbox Code Playgroud)
我的问题是当设备方向改变为横向时,当键盘可见时,底部工具栏消失.我看到它快速上升.我不知道如何解决这个问题.有人可以帮忙吗?另外,有没有办法不让键盘跨越分割视图中的两个视图?
Cor*_*rin 10
我也有这个问题,所有我能想到的是解雇键盘并重新显示它(辞职然后再次成为第一响应者).但这似乎非常令人不满意.
另请注意,您应该将rect从屏幕坐标转换为视图的坐标.(屏幕坐标不旋转.)
CGRect keyboardRect = [[notificationInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
keyboardRect = [[BottomToolBar superview] convertRect:keyboardRect fromView:nil];
Run Code Online (Sandbox Code Playgroud)
更新:您必须注册UIKeyboardWillShowNotification,然后在界面旋转时调用您的操作:)
另请参阅:https: //devforums.apple.com/message/181482#181482
小智 6
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
CGRect keyboardBounds;
[[aNotification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
CGFloat keyboardHeight;
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
keyboardHeight = keyboardBounds.size.height;
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
keyboardHeight = keyboardBounds.size.width;
break;
}
NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect rect = table.frame;
rect.size.height -= keyboardHeight;
[UIView beginAnimations:@"ResizeForKeyboardShow" context:nil];
[UIView setAnimationDuration:animationDuration];
table.frame = rect;
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
CGRect keyboardBounds;
[[aNotification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
CGFloat keyboardHeight;
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
keyboardHeight = keyboardBounds.size.height;
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
keyboardHeight = keyboardBounds.size.width;
break;
}
NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect rectTable = table.frame;
rectTable.size.height += keyboardHeight;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
table.frame = rectTable;
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)