键盘弹出时,UIPopoverController动画

时间:2010-07-27 15:26:50

标签: iphone xcode ipad animation uipopovercontroller

Heey,

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

当键盘出现时,Popover会动画显示以适应。有人知道如何禁用它吗?

谢谢

2 个答案:

答案 0 :(得分:0)

我不认为你可以除了使弹出窗口的高度更小......它就像这样做,所以当你的键盘弹出时,没有任何一个弹出窗口被它覆盖(因此它缩小了),但我发现它是有时很烦人,因为它搞乱了表视图(不能让它们一直滚动并且不得不调整它们的大小)

答案 1 :(得分:0)

如果它实际上对屏幕的更好部分进行了动画效果会很棒,我认为你的意思是它实际上缩小了popUp,这种情况大多不太好。(我在旋转期间看到的情况)。除非您移动视图,否则无法防止popUp压扁。解决此问题的最佳方法是使用keyBoard暂时移动整个屏幕的整个主要UIView,弹出窗口的大小与弹出窗口的缩小程度如果不移动它将会缩小。你不能只用键盘的大小来移动它,因为popUps up也会受到影响。下面的代码适用于键盘旋转的时间,类似于首次引入时的代码。这很容易,当你旋转屏幕时EXCept,然后事情变得棘手......

换句话说,有时你的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:”代码后记录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];
            }
        }