【问题标题】:Properly place MPMoviePlayerController inside UIView in Swift在 Swift 中将 MPMoviePlayerController 正确放置在 UIView 中
【发布时间】:2015-02-27 00:12:12
【问题描述】:

我正在尝试使用 MPMoviePlayerController 提供视频播放。

我在 tableViewCell 中添加了一个 UIView,并向 UIView 添加了自动布局约束。现在,我想将 MPMoviePlayerController 添加到 UIView,使其大小与 UIView 完全相同,并采用所有约束。

我的代码不起作用。 (不幸的是我不能发布图片)。我的 MPMoviePlayerController 没有与 UIView 正确对齐;它在下方和左侧。我试图让它具有与 UIView 完全相同的框架和位置。

我的代码如下:

@IBOutlet weak var movieView: UIView! //connected via storyboard
var moviePlayer:MPMoviePlayerController!

override func awakeFromNib() {
    super.awakeFromNib()

    var videoURL:NSURL!
    moviePlayer = MPMoviePlayerController(contentURL: videoURL)
    moviePlayer.view.frame = movieView.bounds
    moviePlayer.view.center = movieView.center
    //moviePlayer.shouldAutoplay = true
    //moviePlayer.controlStyle = MPMovieControlStyle.Embedded
    //moviePlayer.scalingMode = MPMovieScalingMode.AspectFit
    movieView.addSubview(moviePlayer.view)
    moviePlayer.prepareToPlay()
}

我不确定是什么问题。我已经尝试了很多这样的方法,比如使用 CGRectMake 设置电影播放器​​的帧,并设置缩放模式,如代码中注释的那样。

非常感谢任何帮助

【问题讨论】:

    标签: swift uiview autolayout frame mpmovieplayercontroller


    【解决方案1】:

    我自己想通了。

    moviePlayer.view.frame = movieView.bounds
    moviePlayer.view.center = CGPointMake(CGRectGetMidX(movieView.bounds), CGRectGetMidY(movieView.bounds))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多