3

The app only supports the potrait mode. Two questions should be displayed, but they are rotated accordingly. So the players can see the questions well, no matter where they sit.

Anyway, it seems that the bounding box is not rotated while rotating.

ZStack {
        HStack {
            GeometryReader { proxy in
                Text(challenge)
                    .rotationEffect(Angle(degrees: 90), anchor: .center)
                    .frame(maxWidth: proxy.size.height, minHeight: proxy.size.width)
                    .foregroundColor(.red)
                    .font(.largeTitle)
                    .background(Color.blue)
            }
            Spacer()
            GeometryReader { proxy in
                Text(challenge)
                    .rotationEffect(Angle(degrees: 270), anchor: .center)
                    .frame(maxWidth: proxy.size.height, minHeight: proxy.size.width)
                    .foregroundColor(.red)
                    .font(.largeTitle)
                    .background(Color.blue)
            }
        }
    }

I have tried many different things. I left out the GeometryReader and worked with 'fixedSize()`. Then I get a one-liner that goes across the screen.

I have also tried this solution, but it does not work as expected.

My result is always a text which does not use the full width. (The overlapping is just another mistake, but I will definitely get that under control).

enter image description here

What I actually want to have: enter image description here

kuzdu
  • 7,124
  • 1
  • 51
  • 69

1 Answers1

9

Here is a demo of possible approach. Prepared with Xcode 12.1 / iOS 14.1

demo

struct DemoView: View {
    var body: some View {
        HStack {
            RotatedText(text: lorem, angle: Angle(degrees: 90))
            RotatedText(text: lorem, angle: Angle(degrees: -90))
        }
    }
}

struct RotatedText: View {
    let text: String
    let angle: Angle
    var color: Color = .blue
    
    var body: some View {
        color.overlay(
            GeometryReader { gp in
                VStack {
                    Text(text)
                        .frame(width: gp.size.height, height: gp.size.width)
                        .rotationEffect(angle)
                }.frame(width: gp.size.width, height: gp.size.height)
            }
        )
    }
}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690