AVPictureInPictureController - 自定义PopOver不显示

时间:2016-08-21 12:24:19

标签: ios swift avplayer avplayerlayer

我在AVPPlayer中使用了AVPictureInPictureController并将其初始化为AVPlayerLayer。

- (id)initWithFrame:(CGRect)frame contentURL:(NSURL*)contentURL
{
    self = [super initWithFrame:frame];
    if (self) {

        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:contentURL];
        self.moviePlayer = [AVPlayer playerWithPlayerItem:playerItem];
        playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer];

        if ([AVPictureInPictureController isPictureInPictureSupported])
        {
            self.avVPictureInPictureController = [[AVPictureInPictureController alloc] initWithPlayerLayer:playerLayer];
        }


        [playerLayer setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];


        [self.moviePlayer seekToTime:kCMTimeZero];
        [self.layer addSublayer:playerLayer];


        self.contentURL = contentURL;

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerFinishedPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];

        [self initializePlayer:frame];
    }
    return self;
}

现在,当我尝试提供FPPopoverController(一个自定义类来在iPhone和iPad上展示PopOvers)时,它并没有在屏幕上显示。

我使用以下代码来展示FPPopOverController

//That's how I call

 self.audioSubtitlePopoverController.presentPopoverFromPoint(point)


//Definition of presentPopoverFromPoint  

-(void)presentPopoverFromPoint:(CGPoint)fromPoint
{
    self.origin = fromPoint;

    //NO BORDER
    if(self.border == NO)
    {
        _viewController.title = nil;
        _viewController.view.clipsToBounds = YES;
    }

    _contentView.relativeOrigin = [_parentView convertPoint:fromPoint toView:_contentView];

    [self.view removeFromSuperview];
    NSArray *windows = [UIApplication sharedApplication].windows;
    if(windows.count > 0)
    {
          _parentView=nil;
        _window = [windows objectAtIndex:0];
        //keep the first subview
        if(_window.subviews.count > 0)
        {
            _parentView = [_window.subviews lastObject];

            NSLog(@"%@ %@",_parentView,_viewController);
            [_parentView addSubview:self.view];
            [_viewController viewDidAppear:YES];
            [self.view bringSubviewToFront:_parentView];

        }

   }
    else
    {
        [self dismissPopoverAnimated:NO];
    }



    [self setupView];
    self.view.alpha = 0.0;
    [UIView animateWithDuration:0.2 animations:^{

        self.view.alpha = self.alpha;
    }];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"FPNewPopoverPresented" object:self];

    //navigation controller bar fix
    if([_viewController isKindOfClass:[UINavigationController class]])
    {
        UINavigationController *nc = (UINavigationController*)_viewController;
        UINavigationBar *b = nc.navigationBar;
        CGRect bar_frame = b.frame;
        bar_frame.origin.y = 0;
        b.frame = bar_frame;
    }
}

即使从视图出现也不起作用

self.audioSubtitlePopoverController.presentPopoverFromView(self.view)
// Definition of presentPopoverFromView
-(void)presentPopoverFromView:(UIView*)fromView
{
    SAFE_ARC_RELEASE(_fromView);
    _fromView = SAFE_ARC_RETAIN(fromView);
    [self presentPopoverFromPoint:[self originFromView:_fromView]];
}

任何人都可以提供帮助。不胜感激。

1 个答案:

答案 0 :(得分:1)

FPPopover已弃用。

您应该使用native Possibility来显示弹出窗口或WEPopover