質問編集履歴
1
コードの記載の為
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,19 +14,7 @@
|
|
14
14
|
|
15
15
|
```の所で 「Type "someView" has no member "snapShot"」のエラーになります。
|
16
16
|
|
17
|
-
普通に画像を添付する場合には
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
```Swift
|
22
|
-
|
23
|
-
vc.addImage(UIImage(named: "Twitter.png"))
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
等で良いと思うのですが、
|
30
18
|
|
31
19
|
|
32
20
|
|
@@ -39,3 +27,121 @@
|
|
39
27
|
色々と書きなおしても、そこでエラーになってしまいます。
|
40
28
|
|
41
29
|
ご回答よろしくお願いします。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
コードは以下になります。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```Swift
|
38
|
+
|
39
|
+
import UIKit
|
40
|
+
|
41
|
+
import Social
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
public extension UIView {
|
46
|
+
|
47
|
+
func snapShot() -> UIImage {
|
48
|
+
|
49
|
+
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 1)
|
50
|
+
|
51
|
+
drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
|
52
|
+
|
53
|
+
let image = UIGraphicsGetImageFromCurrentImageContext()
|
54
|
+
|
55
|
+
UIGraphicsEndImageContext()
|
56
|
+
|
57
|
+
return image
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
class GameViewController: UIViewController {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
var myComposeView : SLComposeViewController!
|
70
|
+
|
71
|
+
var myTwitterButton: UIButton!
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
override func viewDidLoad() {
|
76
|
+
|
77
|
+
super.viewDidLoad()
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
// Twitterボタン.
|
84
|
+
|
85
|
+
myTwitterButton = UIButton()
|
86
|
+
|
87
|
+
myTwitterButton.frame = CGRectMake(0,0,100,100)
|
88
|
+
|
89
|
+
myTwitterButton.layer.masksToBounds = true
|
90
|
+
|
91
|
+
myTwitterButton.setTitle("Twitter", forState: UIControlState.Normal)
|
92
|
+
|
93
|
+
myTwitterButton.titleLabel?.font = UIFont.systemFontOfSize(CGFloat(20))
|
94
|
+
|
95
|
+
myTwitterButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
|
96
|
+
|
97
|
+
myTwitterButton.layer.position = CGPoint(x: self.view.frame.width/2, y:self.view.frame.height/2)
|
98
|
+
|
99
|
+
myTwitterButton.tag = 1
|
100
|
+
|
101
|
+
myTwitterButton.addTarget(self, action: #selector(GameViewController.onPostToTwitter(_:)), forControlEvents: .TouchUpInside)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
// buttonをviewに追加.
|
106
|
+
|
107
|
+
self.view.addSubview(myTwitterButton)
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
// ボタンイベント.
|
114
|
+
|
115
|
+
func onPostToTwitter(sender : AnyObject) {
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// SLComposeViewControllerのインスタンス化.
|
120
|
+
|
121
|
+
// ServiceTypeをTwitterに指定.
|
122
|
+
|
123
|
+
myComposeView = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
// 投稿するテキストを指定.
|
128
|
+
|
129
|
+
myComposeView.setInitialText("Twitter Test")
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
// 投稿する画像を指定.
|
134
|
+
|
135
|
+
myComposeView.addImage(UIView.snapShot())//エラーの部分
|
136
|
+
|
137
|
+
// myComposeViewの画面遷移.
|
138
|
+
|
139
|
+
self.presentViewController(myComposeView, animated: true, completion: nil)
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
```
|