嘿,
在我的 iPad 应用程序中,我有一个 UIPopoverController 和一个包含一些文本字段的 UIViewController。
当键盘出现时,弹出框会被动画以适应。有人知道如何禁用它吗?
谢谢
嘿,
在我的 iPad 应用程序中,我有一个 UIPopoverController 和一个包含一些文本字段的 UIViewController。
当键盘出现时,弹出框会被动画以适应。有人知道如何禁用它吗?
谢谢
我认为除了使弹出框的高度更小之外,您无法做到……这样做是这样的,所以当您的键盘弹出时,弹出框不会被它覆盖(因此它会缩小),但是我发现它有时很烦人因为它弄乱了表格视图(不能让它们一直滚动并且不得不调整它们的大小)
如果它确实动画到屏幕的更好部分会很棒,我认为你的意思是它实际上缩小了弹出窗口,这主要是不好的。(在我的情况下,我在旋转过程中看到)。除非您移动视图,否则您无法阻止弹出窗口被挤压。处理此问题的最佳方法是使用键盘将整个屏幕的整个主 UIView 暂时向上移动,这取决于弹出窗口大小之间的差异,如果您不向上移动它,弹出窗口会缩小多少.. . 你不能只按键盘的大小将它向上移动,因为弹出的高度也会受到影响。下面的代码用于键盘旋转时的代码,类似的代码用于首次引入时的代码。很容易做到,除了当你旋转屏幕时,事情就会变得棘手......
换句话说,有时你的 UIView 根本不会移动,有时它会向上移动 170 点。
//-----------------找到键盘顶部(也用于“didRotate”)----非常方便,//花了我几个小时才弄清楚绝对总是有效的topOfKeyboard,所以给你。--------
//--------------------------------------------------------------------------------
- (void)keyboardWillShow:(NSNotification*)notification
{
NSLog(@" keyboardWillShow");
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
NSDictionary* info = [notification userInfo];
keyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardRect = [(UIView*)keyWindow convertRect:keyboardRect toView:mainViewController.view];
keyboardIsVisible = TRUE;
topOfKeyboard = keyboardRect.origin.y;
棘手的部分是找到 PopUp 底部,因为弹出窗口本身或 convertRect:toView: 代码中似乎有代码使原点变得易碎,(如果您尝试在“convertRect:toView:”代码之后“查看”原点),它想在旋转过程中移动并处于不同的位置,(或其中一个超级视图)所以底部计算有时会出现不同的结果(不可预测),因为不同元素的旋转过程的异步过程可能是因为 popUp 本身在弹出窗口中有很多超级视图。(要查看弹出窗口的实际问题,并且必须有键盘影响弹出窗口,向上移动整个视图,然后在“convertRect:toView:”代码之后记录弹出窗口的“原点”和“大小”)......“原点” “ 一世'
更新:(如果您从弹出窗口向下移动大约 3 个超级视图,就会出现这种情况......(下面的代码是“didRotate”ipad 类型的代码。也就是说,弹出窗口有几个超级视图才能获得投射到正确框架顶部的那个
UIPopoverController 可能应该有一个属性,该属性具有在其中旋转后预测的原点,在一种“将旋转”类型的代码中,(因为键盘问题),而不仅仅是“popoverContentSize”,(也应该将没有键盘的 popoverContentSize 包含为另一个变量,“..无论如何这就是我必须这样做的方式,请参见下面的代码。
//--------------------------------------------------------------------------------
- (void) checkRotation
{
NSLog(@" ");
NSLog(@"checkRotation");
if (wasOffset)
{
wasOffset = false;
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:0.2f];
CGRect frame = carousel.frame;
frame.origin.y += offset;
carousel.frame = frame;
[UIImageView commitAnimations];
[popPickerController presentPopoverFromRect:zoneButton.frame inView:[zoneButton superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
if (popPickerController.popoverVisible)
{
if (keyboardIsVisible)
{
wasOffset = false;
[popPickerController presentPopoverFromRect:zoneButton.frame inView:[zoneButton superview]
permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
upView3 = [[[popPickerController.contentViewController.view superview] superview] superview]; //hey it works... :o)
//NSLog(@" ");
//NSLog(@"upView3.frame.origin.x = %f",upView3.frame.origin.x);
//NSLog(@"upView3.frame.origin.y = %f",upView3.frame.origin.y);
//NSLog(@"upView3.frame.size.height = %f",upView3.frame.size.height);
//NSLog(@"upView3.frame.size.width = %f",upView3.frame.size.width);
//NSLog(@" ");
popUpRect.origin.x = upView3.frame.origin.x;
popUpRect.origin.y = upView3.frame.origin.y;
popUpRect.size.height = popUpSize.height;
popUpRect.size.width = popUpSize.width; //you must save the size because the keyboard destroys it before you can use it. very tricky....
//NSLog(@" ");
//NSLog(@"popUpRect.origin.x = %f",popUpRect.origin.x);
//NSLog(@"popUpRect.origin.y = %f",popUpRect.origin.y);
//NSLog(@"popUpRect.size.height = %f",popUpRect.size.height);
//NSLog(@"popUpRect.size.width = %f",popUpRect.size.width);
//NSLog(@" ");
//NSLog(@" ");
//NSLog(@"keyboardIsVisible = %d", keyboardIsVisible);
//NSLog(@" ");
//NSLog(@"keyboardRect.origin.x = %f",keyboardRect.origin.x);
//NSLog(@"keyboardRect.origin.y = %f",keyboardRect.origin.y);
//NSLog(@"keyboardRect.size.height = %f",keyboardRect.size.height);
//NSLog(@"keyboardRect.size.width = %f",keyboardRect.size.width);
//NSLog(@"topOfKeyboard = %f",topOfKeyboard);
CGFloat bottomOfPicker = popUpRect.origin.y + popUpRect.size.height - amountShadowCanEncroach;
//NSLog(@" ");
//NSLog(@"bottomOfPicker = %f",bottomOfPicker);
//NSLog(@"topOfKeyboard = %f",topOfKeyboard);
//NSLog(@" ");
if (bottomOfPicker > topOfKeyboard)
{
wasOffset = true;
offset = bottomOfPicker - topOfKeyboard;
NSLog(@"offset = %f",offset);
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:0.2f];
CGRect frame = carousel.frame;
frame.origin.y -= offset;
carousel.frame = frame;
[UIImageView commitAnimations];
}
}
[popPickerController presentPopoverFromRect:zoneButton.frame inView:[zoneButton superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
and moving the main UIView back
//-----------------------------------------------------------------------------
- (void) searchDidEndEditing
{
NSLog(@"searchDidEndEditing");
keyboardIsVisible = false;
if (wasOffset)
{
wasOffset = false;
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:0.2f];
CGRect frame = mainView.frame;
frame.origin.y += offset;
mainView.frame = frame;
[UIImageView commitAnimations];
if (zoneButton.selected)
[popPickerController presentPopoverFromRect:zoneButton.frame inView:[zoneButton superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}