【问题标题】:UIPopoverController animates when keyboard pops upUIPopoverController 在键盘弹出时动画
【发布时间】:2010-07-27 15:26:50
【问题描述】:

嘿,

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

当键盘出现时,弹出框会被动画以适应。有人知道如何禁用此功能吗?

谢谢

【问题讨论】:

  • 你有没有想过这个问题?我也面临同样的问题。
  • 不,我没有。仍然困扰着我:/
  • 嘿,从头开始后,我能够解决这个问题。事实证明,我创建了自己的 UIViewController 类,它只是添加了一些功能,比如完成块。好吧,显然我在这个类中放了一些代码来为键盘设置动画。当我意识到这一点时,我觉得有点傻,但我想我会回电话说我的弹出窗口不再动画了。实际的弹出窗口将移动,但控件将保持在其中的固定位置。我的问题是文本字段是双重动画。我认为我们有不同的问题,即使它们听起来很相似。

标签: iphone xcode ipad animation uipopovercontroller


【解决方案1】:

我认为除了使弹出框的高度更小之外,您无法做到...这样做是这样的,所以当您的键盘弹出时,弹出框不会被它覆盖(因此它会收缩),但是我发现它是有时很烦人,因为它弄乱了表格视图(不能让它们一直滚动并不得不调整它们的大小)

【讨论】:

    【解决方案2】:

    如果它确实动画到屏幕的更好部分会很棒,我认为你的意思是它实际上缩小了弹出窗口,这主要是不好的。(在我的情况下我在旋转过程中看到)。除非您移动视图,否则您无法阻止弹出窗口被挤压。处理此问题的最佳方法是使用键盘暂时将整个屏幕的整个主 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”之后“查看”原点:" 代码),它想在旋转过程中移动并处于不同的位置,(或其中一个超级视图)所以底部计算有时会出现不同的结果,(不可预测)因为不同元素的旋转过程的异步过程可能是因为弹出窗口本身在弹出窗口中有许多超级视图。 (要查看弹出窗口的实际问题,并且必须有键盘影响弹出窗口,向上移动整个视图,然后在“convertRect:toView:”代码之后记录弹出窗口的“原点”和“大小”)......“原点” “我说的是框架在使用“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];
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      • 2021-01-16
      相关资源
      最近更新 更多