简体   繁体   中英

Swift: Can't make the PhotoEditPreviewController's background transparent when adding it on top of another view

I'm placing PhotoEditPreviewController on top of a custom view, which is initialized by setting a transparent image. There is a SpriteEditController in the PhotoEditPreviewController used for text editing. In the Hierarchy structure of the views, I can see that there is a GLKView which is showing transparent in iPhone 6 and 6s but takes a black background color on iPhone 7, 8 and 10(X). I need that GLKView to be transparent I've tried getting this GLView from the views and setting its layer and background color. But nothing seems to work on these devices.

查看层次结构

You will have to use PhotoEditPreviewController 's delegate to set the background color. Something like this should do it:

photoEditPreviewController.delegate = self

and then

extension ViewController: PhotoEditPreviewControllerDelegate {
  func photoEditPreviewControllerResetProxyZooming(_ photoEditPreviewController: PhotoEditPreviewController) {
  }

  func photoEditPreviewControllerPreviewEnabled(_ photoEditPreviewController: PhotoEditPreviewController) -> Bool {
    return true
  }

  func photoEditPreviewControllerDidChangePhotoEditModel(_ photoEditPreviewController: PhotoEditPreviewController) {
  }

  func photoEditPreviewControllerPreviewScale(_ photoEditPreviewController: PhotoEditPreviewController) -> CGFloat {
    return 1
  }

  func photoEditPreviewControllerBackgroundColor(_ photoEditPreviewController: PhotoEditPreviewController) -> UIColor {
    // Return the desired background color here.
    return .clear
  }

  func photoEditPreviewControllerProxyZoomingActive(_ photoEditPreviewController: PhotoEditPreviewController) -> Bool {
    return false
  }

  func photoEditPreviewControllerPreviewInsets(_ photoEditPreviewController: PhotoEditPreviewController) -> UIEdgeInsets {
    return .zero
  }

  func photoEditPreviewControllerRenderMode(_ photoEditPreviewController: PhotoEditPreviewController) -> PESDKRenderMode {
    return .all
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM