How to add QLPreviewController as Subview in objective C

后端 未结 2 413
陌清茗
陌清茗 2020-12-28 09:04

Is it possible to add QLPreviewController to UIView as sub view.

I tried like this

[self.view addSubview:previewViewController.view] 
2条回答
  •  滥情空心
    2020-12-28 09:50

    Yes its possible, see the code below:

    QLPreviewController* preview = [[QLPreviewController alloc] init];
    preview.dataSource = self;
    preview.delegate = self;
    [self addChildViewController:preview];//*view controller containment
    //set the frame from the parent view
    CGFloat w= self.quickLookView.frame.size.width; 
    CGFloat h= self.quickLookView.frame.size.height;
    preview.view.frame = CGRectMake(0, 0,w, h);
    [self.quickLookView addSubview:preview.view];    
    [preview didMoveToParentViewController:self];
    //save a reference to the preview controller in an ivar
    self.previewController = preview;
    

提交回复
热议问题