iOS 8 Popover控制器不会解雇

时间:2014-12-18 00:26:37

标签: ios objective-c ios8

我有三个函数和一个属性,用于控制我的弹出窗口,如下所示:

-(void)dismissPopoverIfPresentAnimated:(BOOL)animated
{
    if (self.currentPopover)
    {
        [self.currentPopover dismissPopoverAnimated:animated];
        self.currentPopover = nil;
    }
}

-(void)presentViewController:(UIViewController *)viewController inView:(UIView *)view fromRect:(CGRect)rect suppressArrow:(BOOL)suppressArrow
{
//Did the user just tap on a button to bring up the same controller that's already displayed?
//If so, just dismiss the current controller.
BOOL closeOnly = NO;

if (self.currentPopover)
{
    UIViewController *currentController = [self.currentPopover.contentViewController isKindOfClass:UINavigationController.class] ? ((UINavigationController *)self.currentPopover.contentViewController).topViewController : self.currentPopover.contentViewController;
    UIViewController *newController = [viewController isKindOfClass:UINavigationController.class] ? ((UINavigationController *)viewController).topViewController : viewController;
    if ([currentController isKindOfClass:newController.class])
        closeOnly = YES;

    [self dismissPopoverIfPresentAnimated:NO];

}

if (!closeOnly)
    {
        self.currentPopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
        self.currentPopover.backgroundColor = [UIColor whiteColor];
        [self.currentPopover presentPopoverFromRect:rect inView:view permittedArrowDirections:(suppressArrow ? 0 : UIPopoverArrowDirectionAny) animated:YES];
    }
}
  • (instancetype)initWithContentViewController:(UIViewController )viewController { self = [super initWithContentViewController:[[UIViewController alloc] init]]; 如果(自我) {     UIViewController contentViewController = super.contentViewController;     [contentViewController addChildViewController:viewController];     [viewController didMoveToParentViewController:contentViewController];     [contentViewController.view addSubview:viewController.view];

    [self setPopoverContentSize:viewController.preferredContentSize animated:NO];
    

    } 回归自我; }

这在iOS 7中运行良好,但在iOS 8中,问题是对presentPopoverFromRect的调用与项目实际显示在屏幕上之间存在延迟。因此,如果用户双击按钮以显示弹出窗口,则第一次点击将正确解除,然后"开始"显示新控制器。第二次点击将进行解除调用(弹出窗口尚未显示)然后不显示新控制器(这是一个设计功能,因此单击按钮将显示弹出窗口,再次单击它将隐藏它)。 问题是,解除弹出窗口的调用实际上并不起作用,弹出窗口会显示出来。那时我无法摆脱它,因为我的财产是零,我认为它没有显示。

我的猜测是这是一个iOS 8的错误,在某种情况下,解雇不会看到一个可见的弹出窗口因此没有做任何事情,相反,它应该阻止它出现。

哦,最后一点是对presentViewController的调用总是在主线程上完成。

0 个答案:

没有答案