My app works fine in portrait orientation but when i turn to landscape mode I see white square trough half view.
What's the problem?
Code of movie player
moviePlayer = MPMoviePlayerController(contentURL: stream)
moviePlayer.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
moviePlayer.view.sizeToFit()
self.view.addSubview(moviePlayer.view)
moviePlayer.fullscreen = true
moviePlayer.controlStyle = MPMovieControlStyle.Embedded
}
You need to resize moviePlayer
when its superview's bounds change.
One solution is to move this line:
moviePlayer.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
Into viewWillLayoutSubviews
(if this is a view controller subclass) or layoutSubviews
(if this is a view subclass).
Another is to use auto-layout instead of manual layout.
As you are not using autolayout
, you must update the view's frame when orientation is done, to do so you can use the method
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}
This methods is called every time when a orientation change is done and here you can update or set the frame of view to your needs.
Another way is to use Autolayout which is much effective.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.