質問編集履歴
4
画像取得コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,27 +32,119 @@
|
|
32
32
|
|
33
33
|
```swift
|
34
34
|
|
35
|
-
|
35
|
+
// カメラの呼び出し
|
36
36
|
|
37
|
-
|
37
|
+
func onClickPhotoAction() {
|
38
38
|
|
39
|
-
|
39
|
+
isNewPhoto = true
|
40
40
|
|
41
|
-
|
41
|
+
getViewIns()?.hideActionSheet()
|
42
42
|
|
43
|
-
controller.
|
43
|
+
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
44
44
|
|
45
|
-
controller
|
45
|
+
let controller = UIImagePickerController()
|
46
46
|
|
47
|
-
controller.
|
47
|
+
controller.delegate = self
|
48
48
|
|
49
|
-
controller.
|
49
|
+
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
50
50
|
|
51
|
-
|
51
|
+
controller.navigationBar.barTintColor = const.baseGreenColor
|
52
52
|
|
53
|
+
controller.navigationBar.tintColor = UIColor.whiteColor()
|
54
|
+
|
55
|
+
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
56
|
+
|
53
|
-
self.presentViewController(controller, animated: true, completion: nil)
|
57
|
+
self.presentViewController(controller, animated: true, completion: nil)
|
54
58
|
|
55
59
|
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
// 撮影が終わって画像を取得するコード
|
66
|
+
|
67
|
+
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
|
68
|
+
|
69
|
+
if info[UIImagePickerControllerOriginalImage] != nil {
|
70
|
+
|
71
|
+
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
|
72
|
+
|
73
|
+
var orientation: Int?
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
if isNewPhoto == true {
|
78
|
+
|
79
|
+
UIImageWriteToSavedPhotosAlbum(image, self, #selector(BaseResultViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
|
80
|
+
|
81
|
+
let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary
|
82
|
+
|
83
|
+
orientation = metadata?.objectForKey("Orientation") as? Int
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
else {
|
88
|
+
|
89
|
+
switch image.imageOrientation.rawValue {
|
90
|
+
|
91
|
+
case 0:
|
92
|
+
|
93
|
+
orientation = 1
|
94
|
+
|
95
|
+
case 1:
|
96
|
+
|
97
|
+
orientation = 3
|
98
|
+
|
99
|
+
case 2:
|
100
|
+
|
101
|
+
orientation = 8
|
102
|
+
|
103
|
+
case 3:
|
104
|
+
|
105
|
+
orientation = 6
|
106
|
+
|
107
|
+
default:
|
108
|
+
|
109
|
+
break
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
let uuid = NSUUID().UUIDString
|
118
|
+
|
119
|
+
let imageName = "(uuid).PNG"
|
120
|
+
|
121
|
+
let jpgImageName = "(uuid)-thumb.JPG"
|
122
|
+
|
123
|
+
let data = UIImagePNGRepresentation(image)
|
124
|
+
|
125
|
+
let jpgData = UIImageJPEGRepresentation(image, 0.7)
|
126
|
+
|
127
|
+
let localPath = relationData.setFile(imageName, data: data!)
|
128
|
+
|
129
|
+
let _ = relationData.setFile(jpgImageName, data: jpgData!)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
getViewIns()?.hideActionSheet()
|
134
|
+
|
135
|
+
baseModel.saveValuable(NSURL(fileURLWithPath: localPath), orientation: orientation)
|
136
|
+
|
137
|
+
prepareSegue(true)
|
138
|
+
|
139
|
+
resetValuable()
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
picker.dismissViewControllerAnimated(true, completion: nil)
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
56
148
|
|
57
149
|
|
58
150
|
|
3
キャッシュのクリアに関するコードも追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,19 +38,33 @@
|
|
38
38
|
|
39
39
|
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
40
40
|
|
41
|
-
let controller = UIImagePickerController()
|
41
|
+
let controller = UIImagePickerController()
|
42
42
|
|
43
|
-
controller.delegate = self
|
43
|
+
controller.delegate = self
|
44
44
|
|
45
|
-
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
45
|
+
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
46
46
|
|
47
|
-
controller.navigationBar.barTintColor = const.baseGreenColor
|
47
|
+
controller.navigationBar.barTintColor = const.baseGreenColor
|
48
48
|
|
49
|
-
controller.navigationBar.tintColor = UIColor.whiteColor()
|
49
|
+
controller.navigationBar.tintColor = UIColor.whiteColor()
|
50
50
|
|
51
|
-
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
51
|
+
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
52
52
|
|
53
|
-
self.presentViewController(controller, animated: true, completion: nil)
|
53
|
+
self.presentViewController(controller, animated: true, completion: nil)
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
// ライブラリの場合はこれでメモリーが解放されるようですが、撮影した場合はこれでクリア仕切れていない状態です
|
60
|
+
|
61
|
+
キャッシュのクリア
|
62
|
+
|
63
|
+
func clearCache() {
|
64
|
+
|
65
|
+
SDImageCache.sharedImageCache().clearMemory()
|
66
|
+
|
67
|
+
SDImageCache.sharedImageCache().clearDisk()
|
54
68
|
|
55
69
|
}
|
56
70
|
|
2
コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,3 +23,35 @@
|
|
23
23
|
カメラ機能を用いた際にはまた別なメモリーの解放方法があるのだと思うのですが、教えていただけましたらありがたいです。
|
24
24
|
|
25
25
|
宜しくお願いいたします。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
追記:
|
32
|
+
|
33
|
+
```swift
|
34
|
+
|
35
|
+
isNewPhoto = true
|
36
|
+
|
37
|
+
getViewIns()?.hideActionSheet()
|
38
|
+
|
39
|
+
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
40
|
+
|
41
|
+
let controller = UIImagePickerController()
|
42
|
+
|
43
|
+
controller.delegate = self
|
44
|
+
|
45
|
+
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
46
|
+
|
47
|
+
controller.navigationBar.barTintColor = const.baseGreenColor
|
48
|
+
|
49
|
+
controller.navigationBar.tintColor = UIColor.whiteColor()
|
50
|
+
|
51
|
+
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
52
|
+
|
53
|
+
self.presentViewController(controller, animated: true, completion: nil)
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
```
|
1
タイトル
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【Swift】メモリー解放について
|
1
|
+
【Swift】カメラ機能を用いた場合のメモリー解放について
|
test
CHANGED
File without changes
|