in iOS8: UIPopoverController presentPopoverFromRect not work for keyWindow any more

后端 未结 4 1531
臣服心动
臣服心动 2021-02-05 12:03

As titled, in iOS8, [UIPopoverController presentPopoverFromRect] does not work for [UIApplication sharedApplication].keyWindow any more. (It does work in iOS7)

I verifi

4条回答
  •  孤街浪徒
    2021-02-05 12:32

    Try the solution found at this link: http://github.com/werner77/WEPopover

    1st, let's do this code:

    if ([viewController respondsToSelector:@selector(setPreferredContentSize:)]) {
        viewController.preferredContentSize = CGSizeMake(200, 300.0f);
    } else {
        viewController.contentSizeForViewInPopover = CGSizeMake(200.0f, 300.0f);
    }
    
    self.popoverController = [[popoverClass alloc] initWithContentViewController:viewController];
    
    if ([self.popoverController respondsToSelector:@selector(setContainerViewProperties:)]) {
        [self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
    }
    
    self.popoverController.delegate = self;
    
    [self.popoverController presentPopoverFromRect:[sender bounds]
          inView:sender
          permittedArrowDirections:UIPopoverArrowDirectionUp
          animated:YES];
    

    I hope this helps. It was tested and works for iOS6-iOS8.

    PS. Don't forget to check viewDidLoad, and give thanks to the WEPopover Library.

提交回复
热议问题