iOS forces the screen to rotate, which is super easy.

I recently did video playback. Due to some bugs in the screen rotation in the old project, I had to deal with it, so I checked a lot of information and finally solved it perfectly.

1. Create a project and set Device Orientation


2. Implement the following method in AppDelegate:



This property is NO by default, set the property to YES in the interface that needs to be rotated.

3. When it comes to the most critical time, enter the current view controller that you need to rotate:



This method will be called every time the horizontal and vertical screen is switched. It's not over yet, some people will ask, how do I control the screen rotation? Don't worry, please look down

Generally, when we manually control the horizontal and vertical screen switching, we must trigger events, right?

How to manually control the screen rotation?

In the trigger rotation event:



In this way, a forced rotation of an attempt controller is achieved.

demo address: download address

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325524041&siteId=291194637