【问题标题】:UIPopoverController altering location of UIPopoverArrowDirectionUIPopoverController 改变 UIPopoverArrowDirection 的位置
【发布时间】:2011-03-23 06:48:20
【问题描述】:

我想将UIPopoverArrowDirection 向左移动,以使实际箭头不再居中,而是从左侧多出 25%,从右侧多出 75%。

为了帮助理解我的意思,请看两个屏幕截图,我希望它像第二个一样...

问题是没有真正的方法可以深入到 popover 类...

【问题讨论】:

    标签: ios iphone uipopovercontroller


    【解决方案1】:

    通过指定“presentPopoverFromRect”并使该矩形受到足够的约束,内置类已经可以做到这一点。

    以下是直接从导致上述结果的代码中提取的代码。额外的绒毛是因为小齿轮位于 UINavigationBar 中的 UIToolbar 中。 r 是 UIToolbar 的框架,正在调整它以击中正确的位置(箭头),否则它会稍微偏离中心。 MGSettingsView 是视图控制器(其中包含“启用过渡”、“启用夜间模式”等)。

    UINavigationItem *item = scrollView.navbar.topItem;
    UIToolbar *authorTools = (UIToolbar *)[item.rightBarButtonItem customView];
    CGRect r = authorTools.frame;
    r.size.width = 18;
    r.origin.x += 12;
    
    CGSize popoverSize = CGSizeMake(300.f, 500.f);
    MGSettingsView *settingsView = [[MGSettingsView alloc] initWithSize:popoverSize];
    UIPopoverController *poctl = [[UIPopoverController alloc] initWithContentViewController:settingsView];
    settingsView.popover = poctl;
    poctl.delegate = self;
    poctl.popoverContentSize = popoverSize;
    [poctl presentPopoverFromRect:r inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    [settingsView release];
    

    如果这不是您所要求的,那么我认为您最好重新表述您的问题。 :)

    【讨论】:

      【解决方案2】:

      UIPopoverController 类提供了一种从坐标 (Rect) 显示内容的简单方法。您可以设置要自动化的popoverArrowDirection,仅此而已。根据这些信息,系统会自动显示弹出框以适应屏幕并尊重您想要的方向,您不能要求更多。

      【讨论】:

        【解决方案3】:

        在此检查以下方法,您可以为箭头方向提供矩形。

        - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-15
          • 2014-03-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多