###前提・実現したいこと
オリジナルの写真を用いてTinderのような挙動にする
できれば4枚以上で実装する
###発生している問題・エラーメッセージ
'NSData'is not implicitly comvertible to 'Data'; Did you mean to use'as'to explicitly convert?
###該当のソースコード
以下サイトから取ってきたコードです。
http://qiita.com/peg_73_/items/f5134db57695e7d608f4#%E5%8B%95%E3%81%8B%E3%81%AA%E3%81%84%E5%A0%B4%E5%90%88
import UIKit import MDCSwipeToChoose class ViewController: UIViewController, MDCSwipeToChooseDelegate { var swipeCount = 0 var photoURL = [ "http://up.gc-img.net/post_img_web/2013/03/a3a43755438b42d881929eefc7161191_0.jpeg", "http://pic.prepics-cdn.com/pib1298076039/5731792_218x291.gif", "http://omosoku.com/wp-content/uploads/misawa-225x300.gif" ] override func viewDidLoad() { super.viewDidLoad() let swipeView1 = createSwipeView(url: photoURL[0]) self.view.addSubview(swipeView1) let swipeView2 = createSwipeView(url: photoURL[1]) self.view.insertSubview(swipeView2, belowSubview: swipeView1) let swipeView3 = createSwipeView(url: photoURL[2]) self.view.insertSubview(swipeView3, belowSubview: swipeView2) } func createSwipeView(url: String) -> UIView { let options = MDCSwipeToChooseViewOptions() options.delegate = self options.likedText = "LIKE" options.likedColor = UIColor.green options.nopeText = "NOPE" options.nopeColor = UIColor.darkGray let swipeView = MDCSwipeToChooseView( frame: CGRect( x: 0, y: 100, width: self.view.bounds.size.width, height: self.view.bounds.size.height - 300 ), options: options ) let imageURL = NSURL(string: url) swipeView?.imageView.image = UIImage(data: NSData(contentsOfURL: imageURL!)!) return swipeView! } func view(view: UIView!, wasChosenWithDirection direction: MDCSwipeDirection) { if (direction == MDCSwipeDirection.left) { } else { } swipeCount += 1 } }
###試したこと
・Suggestionの通りにしてみると、次々にconvertするように出てきて、結果的に解決はしませんでした。
・ローカルにある画像名を以下のように用いて、一枚だけ表示させることには成功しましたが、
その場合、複数画像を順番に表示させる方法がわかりません。
let imageURL = NSURL(string: url) swipeView?.imageView.image = UIImage(named: "~.png")
###補足情報(言語/FW/ツール等のバージョンなど)
Swift、Xcode8.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/04/15 02:39
2017/04/15 02:57 編集
退会済みユーザー
2017/04/15 03:00
2017/04/15 03:27 編集
退会済みユーザー
2017/04/19 03:51