4

I've searched high and low, but I can't seem to find any mention of this issue anywhere on the internet.

Whenever any SwiftUI animation is playing, and the screen rotates, the orientation change animation is broken.

Instead of gracefully transitioning to the new orientation, my views snap to their final positions, leaving large amounts of white space outside the rendered area while the rest of the iOS screen rotating animation plays out.

This is very apparent in my app, because I've got a non-white background color, and an animation that is usually playing.

I've tried this with my regular code, with a simplified test view, and with some sample code downloaded from a few tutorials, and the behavior always seems to be there. If no animations are playing, the screen rotates fine. If there are animations, the rotation is broken and the view elements jerk to their final position.

Has anyone else experienced this? I literally can't find a mention of this issue anywhere, and I don't know where to even begin with it.

Here's an example of the "simplified test view" I made. Please excuse the annoying VStack/Hstack/Spacer combo, it was just a quick way to fill the screen with an edge-to-edge background color.

struct squareView: View {
    @State var rotationDegrees = 0.0
    
    var body: some View {
        VStack {
            Spacer()
            HStack {
                Spacer()
                Button(action: {
                    withAnimation(.linear(duration: 3)){
                        rotationDegrees += 180
                    }
                }){
                    Rectangle()
                        .fill(Color.white)
                        .cornerRadius(30)
                        .rotationEffect(.degrees(rotationDegrees))
                        .frame(width: 250, height: 250)
                }
                Spacer()
            }
            Spacer()
        }
        .background(Color.black).edgesIgnoringSafeArea(.all)
    }
}

I'd really appreciate it if anyone has any information to share on this. A solution, a workaround, or even just a general direction to look in.

Anything would help. Thanks.


Edit: Since maybe this is a hard one to explain in words, I've recorded a video of the issue.

https://youtu.be/UejK_MTY4Mw

As you can see, when the box is stationary, the screen will rotate just fine, but if it's spinning at all, the animation of iOS changing orientation breaks badly.

(Also, in hindsight, a rotating box was not the best choice of animation when trying to explain an issue with screen rotation. The animation of the box is inconsequential, and the "rotation" I'm having an issue with is that of the device screen changing orientation.)

While the video shows it best, here's some screenshots that attempt to convey the issue.

No Animation:

enter image description here

With Animation:

enter image description here

2 Answers 2

0

we have to change this to black color.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I appreciate the help, but you have misunderstood my issue. I've added a video and some screenshots to better explain what's happening. Also, the spinning box code was really just something to show as an example.
This could work okay as a workaround. I'm not sure how to change the Hosting/View Controller background without reimplementing it though (currently using SwiftUI Lifecycle). Unfortunately, while this could slightly hide the issue, it still won't fix the behavior causing it. Although my box demo doesn't show it well, in an actual view, the broken rotation is a lot more pronounced, with buttons and other UI elements abruptly jumping to their new positions instead of transitioning smoothly.
0

Just wanted to update this since someone seems to have found it recently and was asking (elsewhere).

This issue was fixed by Apple in iOS 15.

I reported the issue to them and they acknowledged it as a bug in SwiftUI itself.

I didn't hear anything after that until just before iOS 15 was released.

iOS 15 fixes this bug. I didn't even have to rebuild my test app. It just worked as of the update.

1 Comment

Has this issue regressed in the iOS 16 beta for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.