質問編集履歴
10
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,7 +13,10 @@
|
|
13
13
|
上からCoordinator.swift、ImagePicker.swift、UIimageExtension.swift、ContentView.swift
|
14
14
|
の4つにコードを打ち込んでいます。
|
15
15
|
|
16
|
+
(SwiftUIのみで構築する場合、どの部分のコードを変更したらいいかというのも教えていただけると嬉しいです。)
|
16
17
|
|
18
|
+
|
19
|
+
|
17
20
|
```import SwiftUI
|
18
21
|
|
19
22
|
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
|
9
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
8
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
作成したカメラアプリのコードです。テンプレートはsingle view app、swiftUIです。
|
12
12
|
環境はxcode11.6、swift5です。
|
13
|
-
Coordinator.swift、ImagePicker.swift、UIimageExtension.swift、ContentView.swift
|
13
|
+
上からCoordinator.swift、ImagePicker.swift、UIimageExtension.swift、ContentView.swift
|
14
14
|
の4つにコードを打ち込んでいます。
|
15
15
|
|
16
16
|
|
@@ -35,4 +35,87 @@
|
|
35
35
|
parent.isPicking = false
|
36
36
|
}
|
37
37
|
}
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
```import SwiftUI
|
43
|
+
|
44
|
+
struct ImagePicker: UIViewControllerRepresentable {
|
45
|
+
|
46
|
+
@Binding var image:Image?
|
47
|
+
@Binding var isPicking:Bool
|
48
|
+
|
49
|
+
func makeCoordinator() -> Coordinator {
|
50
|
+
Coordinator(self)
|
51
|
+
}
|
52
|
+
|
53
|
+
func makeUIViewController(context: Context) -> UIImagePickerController {
|
54
|
+
let picker = UIImagePickerController()
|
55
|
+
picker.sourceType = .camera
|
56
|
+
picker.delegate = context.coordinator
|
57
|
+
return picker
|
58
|
+
}
|
59
|
+
|
60
|
+
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
struct ImagePicker_Previews: PreviewProvider {
|
66
|
+
static var previews: some View {
|
67
|
+
ImagePicker(image: .constant(nil), isPicking: .constant(true))
|
68
|
+
}
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
```import UIKit
|
74
|
+
|
75
|
+
extension UIImage {
|
76
|
+
func redraw() -> UIImage {
|
77
|
+
let format = UIGraphicsImageRendererFormat()
|
78
|
+
format.scale = 1
|
79
|
+
return UIGraphicsImageRenderer(size: size, format: format)
|
80
|
+
.image { context in
|
81
|
+
draw(in: CGRect(origin: .zero, size: size))
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
87
|
+
```import SwiftUI
|
88
|
+
|
89
|
+
struct ContentView: View {
|
90
|
+
@State var image:Image?
|
91
|
+
@State var isPicking = false
|
92
|
+
var body: some View {
|
93
|
+
ZStack {
|
94
|
+
VStack {
|
95
|
+
VStack {
|
96
|
+
Spacer()
|
97
|
+
image?
|
98
|
+
.resizable()
|
99
|
+
.scaledToFit()
|
100
|
+
Spacer()
|
101
|
+
}
|
102
|
+
HStack {
|
103
|
+
Spacer()
|
104
|
+
Button(action: {
|
105
|
+
self.isPicking = true
|
106
|
+
}) {
|
107
|
+
Image(systemName: "camera")
|
108
|
+
Text("カメラ")
|
109
|
+
}.padding()
|
110
|
+
}
|
111
|
+
}
|
112
|
+
if isPicking {
|
113
|
+
ImagePicker(image: $image, isPicking: $isPicking)
|
114
|
+
.edgesIgnoringSafeArea(.all)
|
115
|
+
.transition(.move(edge: .bottom))
|
116
|
+
.animation(.easeInOut)
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
38
121
|
```
|
7
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,15 +12,10 @@
|
|
12
12
|
環境はxcode11.6、swift5です。
|
13
13
|
Coordinator.swift、ImagePicker.swift、UIimageExtension.swift、ContentView.swift
|
14
14
|
の4つにコードを打ち込んでいます。
|
15
|
-
```ここに言語を入力
|
16
|
-
コード
|
17
|
-
```
|
18
15
|
|
19
16
|
|
20
|
-
|
17
|
+
```import SwiftUI
|
21
18
|
|
22
|
-
``` import SwiftUI
|
23
|
-
|
24
19
|
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
|
25
20
|
|
26
21
|
var parent:ImagePicker
|
@@ -39,94 +34,5 @@
|
|
39
34
|
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
|
40
35
|
parent.isPicking = false
|
41
36
|
}
|
42
|
-
} ```
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
ImagePicker.swift
|
48
|
-
|
49
|
-
``` import SwiftUI
|
50
|
-
|
51
|
-
struct ImagePicker: UIViewControllerRepresentable {
|
52
|
-
|
53
|
-
@Binding var image:Image?
|
54
|
-
@Binding var isPicking:Bool
|
55
|
-
|
56
|
-
func makeCoordinator() -> Coordinator {
|
57
|
-
Coordinator(self)
|
58
|
-
|
37
|
+
}
|
59
|
-
|
60
|
-
func makeUIViewController(context: Context) -> UIImagePickerController {
|
61
|
-
let picker = UIImagePickerController()
|
62
|
-
picker.sourceType = .camera
|
63
|
-
picker.delegate = context.coordinator
|
64
|
-
return picker
|
65
|
-
}
|
66
|
-
|
67
|
-
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
struct ImagePicker_Previews: PreviewProvider {
|
73
|
-
static var previews: some View {
|
74
|
-
ImagePicker(image: .constant(nil), isPicking: .constant(true))
|
75
|
-
}
|
76
|
-
|
38
|
+
```
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
UIImageExtention.swift
|
81
|
-
|
82
|
-
|
83
|
-
``` import UIKit
|
84
|
-
|
85
|
-
extension UIImage {
|
86
|
-
func redraw() -> UIImage {
|
87
|
-
let format = UIGraphicsImageRendererFormat()
|
88
|
-
format.scale = 1
|
89
|
-
return UIGraphicsImageRenderer(size: size, format: format)
|
90
|
-
.image { context in
|
91
|
-
draw(in: CGRect(origin: .zero, size: size))
|
92
|
-
}
|
93
|
-
}
|
94
|
-
} ```
|
95
|
-
|
96
|
-
|
97
|
-
ContentView.swift
|
98
|
-
|
99
|
-
``` import SwiftUI
|
100
|
-
|
101
|
-
struct ContentView: View {
|
102
|
-
@State var image:Image?
|
103
|
-
@State var isPicking = false
|
104
|
-
var body: some View {
|
105
|
-
ZStack {
|
106
|
-
VStack {
|
107
|
-
VStack {
|
108
|
-
Spacer()
|
109
|
-
image?
|
110
|
-
.resizable()
|
111
|
-
.scaledToFit()
|
112
|
-
Spacer()
|
113
|
-
}
|
114
|
-
HStack {
|
115
|
-
Spacer()
|
116
|
-
Button(action: {
|
117
|
-
self.isPicking = true
|
118
|
-
}) {
|
119
|
-
Image(systemName: "camera")
|
120
|
-
Text("カメラ")
|
121
|
-
}.padding()
|
122
|
-
}
|
123
|
-
}
|
124
|
-
if isPicking {
|
125
|
-
ImagePicker(image: $image, isPicking: $isPicking)
|
126
|
-
.edgesIgnoringSafeArea(.all)
|
127
|
-
.transition(.move(edge: .bottom))
|
128
|
-
.animation(.easeInOut)
|
129
|
-
}
|
130
|
-
}
|
131
|
-
}
|
132
|
-
} ```
|
6
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,11 +12,11 @@
|
|
12
12
|
環境はxcode11.6、swift5です。
|
13
13
|
Coordinator.swift、ImagePicker.swift、UIimageExtension.swift、ContentView.swift
|
14
14
|
の4つにコードを打ち込んでいます。
|
15
|
+
```ここに言語を入力
|
16
|
+
コード
|
17
|
+
```
|
15
18
|
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
20
|
Coordinator.swift
|
21
21
|
|
22
22
|
``` import SwiftUI
|
@@ -73,7 +73,7 @@
|
|
73
73
|
static var previews: some View {
|
74
74
|
ImagePicker(image: .constant(nil), isPicking: .constant(true))
|
75
75
|
}
|
76
|
-
}```
|
76
|
+
} ```
|
77
77
|
|
78
78
|
|
79
79
|
|
5
title
CHANGED
File without changes
|
body
CHANGED
@@ -128,5 +128,5 @@
|
|
128
128
|
.animation(.easeInOut)
|
129
129
|
}
|
130
130
|
}
|
131
|
-
}
|
131
|
+
}
|
132
132
|
} ```
|
4
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,11 +14,9 @@
|
|
14
14
|
の4つにコードを打ち込んでいます。
|
15
15
|
|
16
16
|
|
17
|
-
```ここに言語を入力
|
18
|
-
コード
|
19
|
-
```
|
20
17
|
|
21
18
|
|
19
|
+
|
22
20
|
Coordinator.swift
|
23
21
|
|
24
22
|
``` import SwiftUI
|
@@ -77,11 +75,13 @@
|
|
77
75
|
}
|
78
76
|
}```
|
79
77
|
|
80
|
-
``` UIImageExtention.swift
|
81
78
|
|
82
79
|
|
83
|
-
|
80
|
+
UIImageExtention.swift
|
84
81
|
|
82
|
+
|
83
|
+
``` import UIKit
|
84
|
+
|
85
85
|
extension UIImage {
|
86
86
|
func redraw() -> UIImage {
|
87
87
|
let format = UIGraphicsImageRendererFormat()
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,11 +14,15 @@
|
|
14
14
|
の4つにコードを打ち込んでいます。
|
15
15
|
|
16
16
|
|
17
|
+
```ここに言語を入力
|
18
|
+
コード
|
19
|
+
```
|
17
20
|
|
18
|
-
#Coordinator.swift
|
19
21
|
|
20
|
-
|
22
|
+
Coordinator.swift
|
21
23
|
|
24
|
+
``` import SwiftUI
|
25
|
+
|
22
26
|
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
|
23
27
|
|
24
28
|
var parent:ImagePicker
|
@@ -37,14 +41,15 @@
|
|
37
41
|
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
|
38
42
|
parent.isPicking = false
|
39
43
|
}
|
40
|
-
}
|
44
|
+
} ```
|
41
45
|
|
42
46
|
|
43
47
|
|
44
|
-
#ImagePicker.swift
|
45
48
|
|
46
|
-
|
49
|
+
ImagePicker.swift
|
47
50
|
|
51
|
+
``` import SwiftUI
|
52
|
+
|
48
53
|
struct ImagePicker: UIViewControllerRepresentable {
|
49
54
|
|
50
55
|
@Binding var image:Image?
|
@@ -70,12 +75,11 @@
|
|
70
75
|
static var previews: some View {
|
71
76
|
ImagePicker(image: .constant(nil), isPicking: .constant(true))
|
72
77
|
}
|
73
|
-
}
|
78
|
+
}```
|
74
79
|
|
80
|
+
``` UIImageExtention.swift
|
75
81
|
|
76
|
-
#UIImageExtention.swift
|
77
82
|
|
78
|
-
|
79
83
|
import UIKit
|
80
84
|
|
81
85
|
extension UIImage {
|
@@ -87,12 +91,12 @@
|
|
87
91
|
draw(in: CGRect(origin: .zero, size: size))
|
88
92
|
}
|
89
93
|
}
|
90
|
-
}
|
94
|
+
} ```
|
91
95
|
|
92
96
|
|
93
|
-
|
97
|
+
ContentView.swift
|
94
98
|
|
95
|
-
import SwiftUI
|
99
|
+
``` import SwiftUI
|
96
100
|
|
97
101
|
struct ContentView: View {
|
98
102
|
@State var image:Image?
|
@@ -125,4 +129,4 @@
|
|
125
129
|
}
|
126
130
|
}
|
127
131
|
}
|
128
|
-
}
|
132
|
+
} ```
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
https://teratail.com/questions/292121
|
6
6
|
|
7
|
-
作成したカメラアプリは、タップで写真を撮影しますが、動画撮影の機能はありません。上記の録画機能を引用し、ボタンなどの位置を特に変えず、動画撮影のみのアプリにする
|
7
|
+
作成したカメラアプリは、タップで写真を撮影しますが、動画撮影の機能はありません。上記の録画機能のコードを引用し、作成したカメラアプリのボタンなどの位置を特に変えず、動画撮影のみのアプリにするにはどのコードをどこに引用すればいいでしょうか?
|
8
8
|
|
9
9
|
|
10
10
|
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
SwiftUIで作成したカメラアプリを、下記のコードの一部を引用して、写真撮影機能ではなく録画機能にして動画撮影アプリにしたいです。
|
1
|
+
SwiftUIで作成したカメラアプリを、下記のコードの一部を引用して、写真撮影機能ではなく録画機能にして動画撮影のみのアプリにしたいです。
|
2
2
|
|
3
3
|
下記が録画機能を追加するために参考にしたコードです。録画機能を一部、作成したアプリに引用しようと思っています(前の質問で回答してくださった方が改変してくれたものになります)
|
4
4
|
|
5
5
|
https://teratail.com/questions/292121
|
6
6
|
|
7
|
+
作成したカメラアプリは、タップで写真を撮影しますが、動画撮影の機能はありません。上記の録画機能を引用し、ボタンなどの位置を特に変えず、動画撮影のみのアプリにする方法はありますでしょうか?
|
7
8
|
|
8
9
|
|
10
|
+
|
9
11
|
作成したカメラアプリのコードです。テンプレートはsingle view app、swiftUIです。
|
10
12
|
環境はxcode11.6、swift5です。
|
11
13
|
Coordinator.swift、ImagePicker.swift、UIimageExtension.swift、ContentView.swift
|