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 ↗Chapters
Code shown on screen · 8 snippets
permittedArrowDirections
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
extension EditorViewController {
func showEditingControlsOrnament() {
let ornament = UIHostingOrnament(sceneAlignment: .bottom, contentAlignment: .center) {
EditingControlsView(model: controlsViewModel)
.glassBackgroundEffect()
}
self.ornaments = [ornament]
editorView.style = .edgeToEdge
}
} UIHostingController
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
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
textField.borderStyle = .roundedRect Overriding preferredContainerBackgroundStyle
class MyViewController: UIViewController {
override var preferredContainerBackgroundStyle: UIContainerBackgroundStyle {
return .glass
}
} Customizing hover style
class CollectionViewCell: UICollectionViewCell {
init(document: PixelArtDocument) {
self.hoverStyle = .init(
effect: .highlight,
shape: .roundedRect(cornerRadius: 8.0))
}
} Checking user interface idiom
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)
} Related sessions
-
22 min -
28 min -
14 min -
26 min -
16 min -
31 min