こんばんは。いつもお世話になっています。早速質問させていただいます。
タイトル通りの質問なのですが、既に同じ様な質問が出ていて、そちらを参考にさせてもらっているのですが、
分からない所があります。
その質問はこちらになります。
ベストアンサーの最後の方に書いてある
swift
1vc.addImage(someView.snapShot()) 2```の所で 「Type "someView" has no member "snapShot"」のエラーになります。 3 4 5```Swift 6vc.addImage(someView.snapShot()) 7```スクリーンショットの場合は上記のコードであっているのでしょうか? 8色々と書きなおしても、そこでエラーになってしまいます。 9ご回答よろしくお願いします。 10 11コードは以下になります。 12 13```Swift 14import UIKit 15import Social 16 17public extension UIView { 18 func snapShot() -> UIImage { 19 UIGraphicsBeginImageContextWithOptions(bounds.size, false, 1) 20 drawViewHierarchyInRect(bounds, afterScreenUpdates: true) 21 let image = UIGraphicsGetImageFromCurrentImageContext() 22 UIGraphicsEndImageContext() 23 return image 24 } 25} 26 27class GameViewController: UIViewController { 28 29 var myComposeView : SLComposeViewController! 30 var myTwitterButton: UIButton! 31 32 override func viewDidLoad() { 33 super.viewDidLoad() 34 35 36 // Twitterボタン. 37 myTwitterButton = UIButton() 38 myTwitterButton.frame = CGRectMake(0,0,100,100) 39 myTwitterButton.layer.masksToBounds = true 40 myTwitterButton.setTitle("Twitter", forState: UIControlState.Normal) 41 myTwitterButton.titleLabel?.font = UIFont.systemFontOfSize(CGFloat(20)) 42 myTwitterButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal) 43 myTwitterButton.layer.position = CGPoint(x: self.view.frame.width/2, y:self.view.frame.height/2) 44 myTwitterButton.tag = 1 45 myTwitterButton.addTarget(self, action: #selector(GameViewController.onPostToTwitter(_:)), forControlEvents: .TouchUpInside) 46 47 // buttonをviewに追加. 48 self.view.addSubview(myTwitterButton) 49 } 50 51 // ボタンイベント. 52 func onPostToTwitter(sender : AnyObject) { 53 54 // SLComposeViewControllerのインスタンス化. 55 // ServiceTypeをTwitterに指定. 56 myComposeView = SLComposeViewController(forServiceType: SLServiceTypeTwitter) 57 58 // 投稿するテキストを指定. 59 myComposeView.setInitialText("Twitter Test") 60 61 // 投稿する画像を指定. 62 myComposeView.addImage(UIView.snapShot())//エラーの部分 63 // myComposeViewの画面遷移. 64 self.presentViewController(myComposeView, animated: true, completion: nil) 65 } 66 67}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/05/08 06:29