简体   繁体   中英

AVPlayerViewController not rotating

My custom AVPlayerViewController won't autorotate if the previous view controller has been instantiated. If I present the AVPlayerViewController, it rotates, and if I present the previous view controller, it rotates. Here's my code for instantiating a view controller :

let vc = self.storyboard!.instantiateViewController(withIdentifier: "MovieVC") as! MovieVC
vc.movie = self.movie
self.navigationController?.pushViewController(vc, animated: true)

In this situation I am creating a copy of the current view controller with different information. If there is no way to fix the autorotating error, is there a different way to present the same view controller?

The problem is that you are not presenting the view controller. You are pushing it. That means that the navigation controller itself is in charge of rotation, so you don't get any special autorotation for this view controller.

The only way to give this view controller its own power over autorotation is to present it:

self.present(vc, animated: true)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM