AVPlayerViewController 是否自动带有 AVPlayer 对象?
Does the AVPlayerViewController automatically come with a AVPlayer object?
swift 和视图控制器范例的新功能。想知道 ViewControllers 是否自动带有它描述的对象,例如,avplayerviewcontroller 是否自动带有准备使用的 avplayer 对象,或者我们是否仍然需要创建一个 avplayer 对象?另一个例子可能是 uitableviewcontroller,它是自动附带一个 tableview 对象还是我们需要在创建 cocoa touch class that subclasses uitableviewcontroller.
之后创建它?
下面是一些编译示例代码,我不一定要创建 avplayer 对象,但似乎该对象已经准备好通过名为 'player' 的 属性 使用:
import UIKit
import AVKit
import AVFoundation
class MeetTheAuthorViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//playBackgroundMusic("bensound-jazzyfrenchy-castlesbackground.mp3")
// Do any additional setup after loading the view.
}
func btn_clicked(_ sender: UIBarButtonItem) {
// Do something
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "videoSegue"
{
//set up the player
let videoURL = Bundle.main.url(forResource: "The Atlanta Goat_ Part One-HD", withExtension: "mp4")
let videoViewController = segue.destination as! AVPlayerViewController
videoViewController.player = AVPlayer(url: videoURL!)
videoViewController.player?.play()
}
}
}
是的。 XYFeatureViewControllers 是方便的 UIViewController
子类。例如 UITableViewController
继承自 UIViewController
,假设它的 view
是 UITableView
类型并且已经符合 UITableViewDelegate
和 UITableViewDataSource
协议。
通常他们会提供委托方法的默认实现,因此 "just work" 马上就可以了。
如果是 UITableView
,我建议使用自定义 UIViewController
并自己添加 UITableView
(s) 以获得完全的灵活性。
例如,UITableViewController
有 UITableView
作为根视图,所以如果你想稍后在屏幕上缩小 tableView(示例),你不能。
在您的自定义 viewController 中,tableView 将是 rootView 的子视图,因此调整它的大小或在其旁边添加第二个都不是问题。
swift 和视图控制器范例的新功能。想知道 ViewControllers 是否自动带有它描述的对象,例如,avplayerviewcontroller 是否自动带有准备使用的 avplayer 对象,或者我们是否仍然需要创建一个 avplayer 对象?另一个例子可能是 uitableviewcontroller,它是自动附带一个 tableview 对象还是我们需要在创建 cocoa touch class that subclasses uitableviewcontroller.
之后创建它?下面是一些编译示例代码,我不一定要创建 avplayer 对象,但似乎该对象已经准备好通过名为 'player' 的 属性 使用:
import UIKit
import AVKit
import AVFoundation
class MeetTheAuthorViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//playBackgroundMusic("bensound-jazzyfrenchy-castlesbackground.mp3")
// Do any additional setup after loading the view.
}
func btn_clicked(_ sender: UIBarButtonItem) {
// Do something
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "videoSegue"
{
//set up the player
let videoURL = Bundle.main.url(forResource: "The Atlanta Goat_ Part One-HD", withExtension: "mp4")
let videoViewController = segue.destination as! AVPlayerViewController
videoViewController.player = AVPlayer(url: videoURL!)
videoViewController.player?.play()
}
}
}
是的。 XYFeatureViewControllers 是方便的 UIViewController
子类。例如 UITableViewController
继承自 UIViewController
,假设它的 view
是 UITableView
类型并且已经符合 UITableViewDelegate
和 UITableViewDataSource
协议。
通常他们会提供委托方法的默认实现,因此 "just work" 马上就可以了。
如果是 UITableView
,我建议使用自定义 UIViewController
并自己添加 UITableView
(s) 以获得完全的灵活性。
例如,UITableViewController
有 UITableView
作为根视图,所以如果你想稍后在屏幕上缩小 tableView(示例),你不能。
在您的自定义 viewController 中,tableView 将是 rootView 的子视图,因此调整它的大小或在其旁边添加第二个都不是问题。