Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2023 Developer ToolsEssentialsSpatial ComputingSwiftUI & UI Frameworks

WWDC23 · 26 min · Developer Tools / Essentials / Spatial Computing / SwiftUI & UI Frameworks

Meet UIKit for spatial computing

Learn how to bring your UIKit app to visionOS. We’ll show you how to build for a new destination, explore APIs and best practices for spatial computing, and take your content into the third dimension when you use SwiftUI with UIKit in visionOS.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

Code shown on screen · 8 snippets

permittedArrowDirections swift · at 16:15 ↗
import UIKit

extension EditorViewController {

    @objc func showDocumentPopover(sender: UIBarButtonItem) {
        let controller = DocumentInfoViewController(document: pixelDocument)
        controller.modalPresentationStyle = .popover
        if let presentationController = controller.popoverPresentationController {
            presentationController.barButtonItem = sender
            if traitCollection.userInterfaceIdiom == .reality {
                presentationController.permittedArrowDirections = .any
            } else {
                presentationController.permittedArrowDirections = .right
            }
        }
        present(controller, animated: true, completion: nil)
    }

}
Ornament swift · at 19:46 ↗
extension EditorViewController {

    func showEditingControlsOrnament() {
        let ornament = UIHostingOrnament(sceneAlignment: .bottom, contentAlignment: .center) {
            EditingControlsView(model: controlsViewModel)
                .glassBackgroundEffect()
        }

        self.ornaments = [ornament]

        editorView.style = .edgeToEdge
    }

}
UIHostingController swift · at 22:45 ↗
extension EditorViewController {

    func showEntityPreview() {
        let entityView = PixelArtEntityView(model: entityViewModel)
        let controller = UIHostingController(rootView: entityView)
        addChild(controller)
        view.addSubview(controller.view)
        controller.didMove(toParent: self)
        prepareEditorInteractions()
    }

}
Using Semantic Colors swift · at 22:46 ↗
private let titleLabelTextField: UITextField = {
    textField.textColor = UIColor.label
    return textField
}()

private let authorLabel: UILabel = {
    label.textColor = UIColor.secondaryLabel
    return label
}()
Adding a recessed appearance to a text field swift · at 22:47 ↗
textField.borderStyle = .roundedRect
Overriding preferredContainerBackgroundStyle swift · at 22:48 ↗
class MyViewController: UIViewController {
    override var preferredContainerBackgroundStyle: UIContainerBackgroundStyle {
        return .glass
    }
}
Customizing hover style swift · at 22:49 ↗
class CollectionViewCell: UICollectionViewCell {
    init(document: PixelArtDocument) {
        self.hoverStyle = .init(
            effect: .highlight, 
            shape: .roundedRect(cornerRadius: 8.0))
    }
}
Checking user interface idiom swift · at 22:50 ↗
func fourFingerSwipe() {
    let gesture = UISwipeGestureRecognizer(
        target: self, 
        action: #selector(self.deleteAll))
    gesture.direction = .left
    if traitCollection.userInterfaceIdiom == .reality {
        gesture.numberOfTouchesRequired = 2
    } else {
        gesture.numberOfTouchesRequired = 4
    }
    self.view.addGestureRecognizer(gesture)
}