Reputation: 11985
I'm trying to put a PHLivePhotoView
into the WelcomeVideoItemViewController
using Storyboard. For this purpose the view with a custom class is configured:
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
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:
Don't forget to check Inherit Module From Target
.
Upvotes: 4