Monday, December 25, 2023
HomeiOS DevelopmentPerceive and calculate iOS display rotation animation

Perceive and calculate iOS display rotation animation


In iOS there may be this animation of display rotation when altering orientation:

demo

In accordance with my observations, the next occurs right here: the display rotates at a proper angle, on the identical time the scale of the seen space easily modifications, which in my instance is highlighted in purple.

I would like to grasp how the scale of this seen space is calculated through the animation course of.

There are the next preliminary knowledge:

length – animation length

targetWidth/targetHeight – display dimensions after rotation

currentWidth/currentHeight – the scale of the seen space on the present time

startTime – animation begin time in milliseconds

To illustrate we now have a perform that can be launched as typically as attainable through the animation course of (ideally 60 instances per second, however not assured – skipping frames is feasible), wherein we should calculate the scale of the seen space on the present time. This perform has a variable currentTime that shops the present time in milliseconds. First, we have to decide the present progress of the animation, let it’s a floating level quantity from 0 to 1, we do it like this:

 progress = (currentTime - startTime) / length;

Subsequent, you need to implement the logic of how the scale of the seen space will change relative to the present progress. I took linear interpolation right here for instance:

 lerp(begin, finish, t) {
     return begin * (1 - t) + finish * t;
 }

begin – preliminary (present) worth

finish – last (goal) worth

t – progress (0..1)

This leads to the next logic:

 if (progress <= 1) {
     currentWidth = lerp(currentWidth, targetWidth, progress);
     currentHeight = lerp(currentHeight, targetHeight, progress);
 } else {
     // Cease execution
 }

With this implementation, the next occurs:

bug

The size of the seen space don’t change as wanted: in portrait orientation on the best, and in panorama orientation from beneath (within the instance on the best), you’ll be able to see how my animation is forward of the iOS system animation.

The query is methods to precisely calculate the scale of the seen space.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments