1. 環境
Xcode 9.3
Swift 4.1
2.実現したいこと
・iOSアプリを作成しています。
・初期画面はserachbarと検索ボタンのみ。
・hogeと検索をかけるとYoutubeの検索結果が表示される。
3.質問事項
searchbarからYoutubeの検索結果へと遷移させる方法について教えていただきたいです。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/09 08:59
回答3件
0
質問の仕方について、以後気をつけます。皆様ご指摘ありがとうございました。
以下の方法で解決できました。
皆様ありがとうございます。
ViewController.swift
import UIKit class ViewController: UIViewController { //テキストフィールド @IBOutlet weak var mySearch: UITextField! //mySearchStringという変数に空文字を設定 var mySearchString = "" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //secondViewに移行するためのコード override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "goYoutube" { // TextFieldから文字を取得 mySearchString = mySearch.text! let secondVc = segue.destination as! secondViewController // 値を渡す secondVc.mySearchString = self.mySearchString } else { //elseのとき } } }
secondViewController.swift
import UIKit import WebKit class secondViewController: UIViewController, WKUIDelegate { var webView: WKWebView! var mySearchString = "" override func loadView() { let webConfiguration = WKWebViewConfiguration() webView = WKWebView(frame: .zero, configuration: webConfiguration) webView.uiDelegate = self view = webView } override func viewDidLoad() { super.viewDidLoad() let myURL:String = "https://www.youtube.com/results?search_query=(mySearchString)" let encURL = URL(string:myURL.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)!) let myRequest = URLRequest(url: encURL!) webView.load(myRequest) }
投稿2018/05/11 07:29
総合スコア24
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
0
springer様
youtube専用ではありませんが、動画を絡ませたアプリを作成しています。
こちらを参考にさせて頂きました!ありがとうございます。
youtubeアプリ作成の過程で、
もしご存知でしたら教えていただきたいことがあります。
現在下記コードにて、youtube動画再生の画面を表示していますが、
「アプリを開く」「検索マーク」等も表示されてしまい邪魔です・・・
動画のプレビューのみすっきりと表示させる方法をご存知でないでしょうか?
・現在の画面
添付
・コード
//youtube
let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback = true config.mediaTypesRequiringUserActionForPlayback = .all webView = WKWebView(frame:CGRect(x:0, y:0, width:self.view.bounds.size.width, height:self.view.bounds.size.hei https://uploads.disquscdn.com/images/2fa4d63119cdf8999e08ebe65e01f0c51ec803f41dc57c96ca7092203d6633bc.png ght / 5) , configuration: config) //url guard let VC2youtubeURL = VC2youtubeURL else { return } let urlString = "https://www.youtube.com/(VC2youtubeURL)" let encodedUrlString = urlString.addingPercentEncoding(withAllowedCharacters:NSCharacterSet.urlQueryAllowed) let url = NSURL(string: encodedUrlString!) let request = NSURLRequest(url: url! as URL) webView.load(request as URLRequest) self.contentView.addSubview(webView)
投稿2018/10/25 12:29
総合スコア33
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
0
ベストアンサー
開発者向けサイトがあるので、こちらを一読することで進めれるのではないかと思います。
https://www.youtube.com/yt/dev/ja/api-resources.html
投稿2018/05/08 08:04
総合スコア1336
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。