Orientation issue occurs While Rotate landscape mode to portrait mode In SwiftUI

49 Views Asked by At

enter image description hereenter image description hereOn a (iOS Minimum Delpolyment target 14.0) following leads to an error: When I created the TextField using UIViewRepresentable, I successfully assigned its value to the @State variable. The rotation worked flawlessly without any errors. However, while implementing MVVM architecture and assigning the variable in the ViewModel class as '@Published var', an issue arose. When rotating from landscape to portrait mode, the screen did not adjust accordingly and remained the same width as in landscape mode. This unexpected behavior is the issue I encountered.

struct SignInView: View {
 @State var emailaddress: String = ""
@State var password: String = ""
    
    var body: some View {
  VStack(spacing: 15) {
                    NormalSkyFloatingWithIconTextField(text: $emailAddress, placeHolder: "Email Address*", imageName: "EmailIcon", characterRangeDelegate: self, textFieldValue: TextFieldValues.EmailAddress)
                        .frame(height: 45)
NormalSkyFloatingTextField_Secure(text: $password, placeHolder: "Password*", characterRangeDelegate: self, textFieldValue: TextFieldValues.PassWord, isSecureTextEntry: viewModel.isPasswordVisible)
 .frame(height: 45)
  }
 }
}
        

While My Textfield i did't face any orientation issue Faced.

struct SignInView: View {
` @StateObject var viewModel = SignInViewModel()`
    
    var body: some View {
  VStack(spacing: 15) {
                    NormalSkyFloatingWithIconTextField(text: $viewModel.emailAddress, placeHolder: "Email Address*", imageName: "EmailIcon", characterRangeDelegate: self, textFieldValue: TextFieldValues.EmailAddress)
                        .frame(height: 45)
                           NormalSkyFloatingTextField_Secure(text: $viewModel.password, placeHolder: "Password*", characterRangeDelegate: self, textFieldValue: TextFieldValues.PassWord, isSecureTextEntry: viewModel.isPasswordVisible)
 .frame(height: 45)
  }
 }
}

class SignInViewModel: ObservableObject {
    
    @Published var emailAddress: String = ""
    @Published var password: String = ""
}

when i implement in MVVM Architecture rotating from landscape to portrait mode, the screen did not adjust accordingly and remained the same width as in landscape mode.

And @StateObject var viewModel = SignInViewModel() i tried @ObservedObject var viewModel = SignInViewModel() also Still face That orientation issue. Please Any Help To fix this issue

0

There are 0 best solutions below