View and Modifier that can be used by importing various frameworks in addition to SwiftUI.
MapKit
You can use Map
.
import SwiftUI
import MapKit
struct SwiftUIView: View {
@State var region: MKCoordinateRegion
var body: some View {
Map(coordinateRegion: $region)
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
let initialCoordinate = CLLocationCoordinate2DMake(40,40)
let span = MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)
let region = MKCoordinateRegion(center: initialCoordinate, span: span)
return SwiftUIView(region: region)
}
}
SpriteKit
You can use SpriteView
.
The GameScene
file is the one used when the Xcode project was created on Multiplatform.
import SwiftUI
import SpriteKit
struct SwiftUIView: View {
let scene: SKScene
var body: some View {
SpriteView(scene: scene)
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
guard let scene = SKScene(fileNamed: "GameScene") as? GameScene else {
abort()
}
scene.scaleMode = .aspectFit
return SwiftUIView(scene: scene)
}
}
AuthenticationServices
You can use SignInWithAppleButton
.
import SwiftUI
import AuthenticationServices
struct SwiftUIView: View {
var body: some View {
SignInWithAppleButton(.continue) { _ in
} onCompletion: { _ in
}
.frame(width: 300.0, height: 44.0)
.signInWithAppleButtonStyle(.black)
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
StoreKit
You can use appStoreOverlay
.
import SwiftUI
import StoreKit
struct SwiftUIView: View {
@State var showOverlay:Bool = false
var body: some View {
Button("App Store Overlay") {
self.showOverlay.toggle()
}
.appStoreOverlay(isPresented: $showOverlay) {
SKOverlay.AppConfiguration(appIdentifier: "687721425", position: .bottom)
}
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
return SwiftUIView()
}
}
AVKit
You can use VideoPlayer
.
The documentation says A view that displays the video content from a player object along with system-supplied playback controls.
, but with tvOS it feels like there is no control.
import SwiftUI
import AVKit
struct SwiftUIView: View {
let player: AVPlayer?
var body: some View {
VideoPlayer(player: player)
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
return SwiftUIView(player: AVPlayer(url: URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")!))
}
}
SceneKit
You can use SceneView
. Please prepare your own scn file.
import SwiftUI
import SceneKit
struct SwiftUIView: View {
let scene: SCNScene?
var body: some View {
SceneView(scene: scene)
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
let scene = SCNScene(named: "Scene.scn")
return SwiftUIView(scene: scene)
}
}
HomeKit
You can use CameraView
.
You will need HMCameraSource
, but it probably cannot be prepared in SwiftUI preview, so please check it on your own.
import SwiftUI
import HomeKit
struct SwiftUIView: View {
let cameraSource:HMCameraSource
var body: some View {
CameraView(source: cameraSource)
}
}
WatchKit
You can use NowPlayingView
.
import SwiftUI
import WatchKit
struct SwiftUIView: View {
var body: some View {
NowPlayingView()
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
Let's use it! HomeKit!
Recommended Posts