当键盘弹出时,UIPopoverController会执行动画。

4

嘿,

我的iPad应用程序中有一个带有一些文本字段的UIViewController的UIPopoverController。

当键盘弹出时,Popover会进行动画调整以适应。有人知道如何禁用此功能吗?

谢谢


你解决了这个问题吗?我也遇到了同样的问题。 - VaporwareWolf
我没有。这仍然困扰着我 :/ - Mats Stijlaart
嘿,在从头开始后,我成功地解决了这个问题。原来是我自己创建了一个UIViewController类,它只是添加了一些功能,比如完成块。好吧,显然我在这个类中放了一些代码来动画化键盘。当我意识到这一点时,我感到有点傻,但我想我会回来告诉大家我的弹出窗口不再动画化了。实际的弹出窗口会移动,但控件将保持在其中的固定位置。我的问题是文本字段正在双重动画。我认为我们虽然听起来问题相似,但问题不同。 - VaporwareWolf
2个回答

0

如果实际上动画到屏幕的更大部分会很好,但我认为你的意思是它实际上缩小了弹出窗口,这通常不太好(这是我在旋转中看到的情况)。除非你移动一个视图,否则你无法防止弹出窗口被挤压。处理这个问题的最好方法是通过将整个主要UIView临时向上移动与键盘大小之间的差距,以及如果你没有将其向上移动,那么该弹出窗口将收缩多少...你不能只是按键盘的大小将其向上移动,因为位于高处的弹出窗口也会受到影响。下面的代码用于键盘旋转时,首次引入时需要类似的代码。当你旋转屏幕时,这变得有点棘手...

换句话说,有时你的UIView根本不会移动,有时它会上移约170个点。

//-----------------找到键盘顶部(也用于“didRotate”)----非常方便, // 花费了我几个小时才找到一个绝对有效的键盘顶部位置,所以这里给你。-------

//--------------------------------------------------------------------------------
- (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:”代码后查看原点),它希望在旋转期间移动并位于不同的位置(或其其中一个超级视图),因此由于可能是弹出窗口本身具有许多下层父视图的异步过程,底部计算有时会出现不同的情况(不可预测)。 (要在弹出窗口和键盘影响弹出窗口的情况下查看问题,请将整个视图向上移动,然后在“convertRect:toView:”代码之后记录popUp的“origin”和“size”)...我所说的“origin”是指将其翻译为主视图(或至少是几个视图)后的框架原点与“convertRect:toView:”代码一起....

更新:(似乎如果您从PopUp向下移动约3个父视图,则不稳定性会消失...(下面的代码在“didRotate”iPad类型的代码中。也就是说,在您可以到达投影在适当框架上方的那个视图之前,PopUp具有几个父视图

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];
            }
        }

0

我认为你不能只是减小弹出窗口的高度...这样做是为了当键盘弹出时,弹出窗口不会被覆盖(因此它会缩回去),但有时我发现它很烦人,因为它会干扰表视图(使它们无法完全滚动并且必须调整大小)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接