-
Notifications
You must be signed in to change notification settings - Fork 16
Interface Builder Usage #2
Copy link
Copy link
Open
Description
Amazing product, thank you for your contribution to the world of tvOS 👍
One thing that took me a little bit to figure out, might be good to put it in your docs or something, but this is an example of how you would make this work in Interface Builder:
// Stub container
class SimpleParallaxContainer: UIView, ParallaxContainer {
func focusChanged(_ focus: ParallaxFocusState) {}
func parallaxShadow(forFocus: ParallaxFocusState, defaultShadow: Shadow) -> Shadow? {
return defaultShadow
}
}
// Because ParallaxView doesn't implement initWith(coder:) you can't place it in Interface Builder.
// This UIView subclass substitutes itself with a ParallaxView at runtime.
class ParallaxPlaceholder: UIView {
override func layoutSubviews() {
super.layoutSubviews()
guard let sup = self.superview else { return } // make sure we have a superview
// Create a container
let cont = SimpleParallaxContainer.init(frame: self.bounds)
// Move all of the placeholder's subviews into the container
self.subviews.forEach { (view) in
let f = view.frame
view.removeFromSuperview()
cont.addSubview(view)
view.frame = f
}
// Create a parallax view, using the container we just built
let pView = ParallaxView<SimpleParallaxContainer>(layerContainer: cont)
// Remove ourselves from the view hierarchy and replace with the parallax view
sup.insertSubview(pView, aboveSubview: self)
pView.frame = self.frame
self.removeFromSuperview()
}
}Definitely no problem if I'm going about this wrong and you feel like pointing it out. Either way, thanks again!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels