kelin
kelin

Reputation: 11985

Add PHLivePhotoView to the storyboard

I'm trying to put a PHLivePhotoView into the WelcomeVideoItemViewController using Storyboard. For this purpose the view with a custom class is configured: Custom class (PHLivePhotoView)

The scene hierarchy:
Hierarchy of a ViewController

The implementation of the custom View Controller:

class WelcomeVideoItemViewController: UIViewController, PHLivePhotoViewDelegate {
    @IBOutlet weak var livePhotoView: PHLivePhotoView!

    @IBOutlet weak var tipImageView: UIImageView!

    @IBOutlet weak var tipLabel: UILabel!


    override func viewDidLoad() {
        super.viewDidLoad()

        print(livePhotoView)
        // Optional(<UIView: 0x7fd161f200b0; frame = (0 0; 320 568); autoresize = RM+BM; layer = <CALayer: 0x60000134ac60>>)

        // Crash here
        livePhotoView.delegate = self
    }
}

So the problem is that the livePhotoView is initialized with a UIView instance, which leads to crash because the UIView has no delegate property. Ho can I make this custom class work?

Xcode 10.2, iOS 12.2, Swift 4.2

Upvotes: 2

Views: 534

Answers (2)

yoAlex5
yoAlex5

Reputation: 34255

Or you can just set class name as PHLivePhotoView

Upvotes: 0

kelin
kelin

Reputation: 11985

I found a workaround for this. First, create a custom PHLivePhotoView subclass:

import PhotosUI

class LivePhotoView: PHLivePhotoView {
}

Then, drag a View to the storyboard and set the custom class for it:

Custom Class

Don't forget to check Inherit Module From Target.

Upvotes: 4

Related Questions