質問編集履歴
4
画像取得コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,18 +15,64 @@
|
|
15
15
|
|
16
16
|
追記:
|
17
17
|
```swift
|
18
|
+
// カメラの呼び出し
|
19
|
+
func onClickPhotoAction() {
|
18
|
-
isNewPhoto = true
|
20
|
+
isNewPhoto = true
|
19
|
-
getViewIns()?.hideActionSheet()
|
21
|
+
getViewIns()?.hideActionSheet()
|
20
|
-
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
22
|
+
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
21
|
-
|
23
|
+
let controller = UIImagePickerController()
|
22
|
-
|
24
|
+
controller.delegate = self
|
23
|
-
|
25
|
+
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
24
|
-
|
26
|
+
controller.navigationBar.barTintColor = const.baseGreenColor
|
25
|
-
|
27
|
+
controller.navigationBar.tintColor = UIColor.whiteColor()
|
26
|
-
|
28
|
+
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
27
|
-
|
29
|
+
self.presentViewController(controller, animated: true, completion: nil)
|
28
30
|
}
|
29
31
|
|
32
|
+
|
33
|
+
// 撮影が終わって画像を取得するコード
|
34
|
+
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
|
35
|
+
if info[UIImagePickerControllerOriginalImage] != nil {
|
36
|
+
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
|
37
|
+
var orientation: Int?
|
38
|
+
|
39
|
+
if isNewPhoto == true {
|
40
|
+
UIImageWriteToSavedPhotosAlbum(image, self, #selector(BaseResultViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
|
41
|
+
let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary
|
42
|
+
orientation = metadata?.objectForKey("Orientation") as? Int
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
switch image.imageOrientation.rawValue {
|
46
|
+
case 0:
|
47
|
+
orientation = 1
|
48
|
+
case 1:
|
49
|
+
orientation = 3
|
50
|
+
case 2:
|
51
|
+
orientation = 8
|
52
|
+
case 3:
|
53
|
+
orientation = 6
|
54
|
+
default:
|
55
|
+
break
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
let uuid = NSUUID().UUIDString
|
60
|
+
let imageName = "(uuid).PNG"
|
61
|
+
let jpgImageName = "(uuid)-thumb.JPG"
|
62
|
+
let data = UIImagePNGRepresentation(image)
|
63
|
+
let jpgData = UIImageJPEGRepresentation(image, 0.7)
|
64
|
+
let localPath = relationData.setFile(imageName, data: data!)
|
65
|
+
let _ = relationData.setFile(jpgImageName, data: jpgData!)
|
66
|
+
|
67
|
+
getViewIns()?.hideActionSheet()
|
68
|
+
baseModel.saveValuable(NSURL(fileURLWithPath: localPath), orientation: orientation)
|
69
|
+
prepareSegue(true)
|
70
|
+
resetValuable()
|
71
|
+
}
|
72
|
+
picker.dismissViewControllerAnimated(true, completion: nil)
|
73
|
+
}
|
74
|
+
|
75
|
+
|
30
76
|
// ライブラリの場合はこれでメモリーが解放されるようですが、撮影した場合はこれでクリア仕切れていない状態です
|
31
77
|
キャッシュのクリア
|
32
78
|
func clearCache() {
|
3
キャッシュのクリアに関するコードも追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,12 +18,19 @@
|
|
18
18
|
isNewPhoto = true
|
19
19
|
getViewIns()?.hideActionSheet()
|
20
20
|
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
21
|
-
|
21
|
+
let controller = UIImagePickerController()
|
22
|
-
|
22
|
+
controller.delegate = self
|
23
|
-
|
23
|
+
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
24
|
-
|
24
|
+
controller.navigationBar.barTintColor = const.baseGreenColor
|
25
|
-
|
25
|
+
controller.navigationBar.tintColor = UIColor.whiteColor()
|
26
|
-
|
26
|
+
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
27
|
-
|
27
|
+
self.presentViewController(controller, animated: true, completion: nil)
|
28
28
|
}
|
29
|
+
|
30
|
+
// ライブラリの場合はこれでメモリーが解放されるようですが、撮影した場合はこれでクリア仕切れていない状態です
|
31
|
+
キャッシュのクリア
|
32
|
+
func clearCache() {
|
33
|
+
SDImageCache.sharedImageCache().clearMemory()
|
34
|
+
SDImageCache.sharedImageCache().clearDisk()
|
35
|
+
}
|
29
36
|
```
|
2
コードの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,4 +10,20 @@
|
|
10
10
|
|
11
11
|
カメラ撮影した場合はクリアされきっておらず、40回ほど撮影するとメモリがいっぱいになりアプリが落ちてしまいます。
|
12
12
|
カメラ機能を用いた際にはまた別なメモリーの解放方法があるのだと思うのですが、教えていただけましたらありがたいです。
|
13
|
-
宜しくお願いいたします。
|
13
|
+
宜しくお願いいたします。
|
14
|
+
|
15
|
+
|
16
|
+
追記:
|
17
|
+
```swift
|
18
|
+
isNewPhoto = true
|
19
|
+
getViewIns()?.hideActionSheet()
|
20
|
+
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
|
21
|
+
let controller = UIImagePickerController()
|
22
|
+
controller.delegate = self
|
23
|
+
controller.sourceType = UIImagePickerControllerSourceType.Camera
|
24
|
+
controller.navigationBar.barTintColor = const.baseGreenColor
|
25
|
+
controller.navigationBar.tintColor = UIColor.whiteColor()
|
26
|
+
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
|
27
|
+
self.presentViewController(controller, animated: true, completion: nil)
|
28
|
+
}
|
29
|
+
```
|
1
タイトル
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
【Swift】メモリー解放について
|
1
|
+
【Swift】カメラ機能を用いた場合のメモリー解放について
|
body
CHANGED
File without changes
|