2

I have a SwiftUI app originally coded for iOS, that I would like to run at mac as well. I have checked Mac in Deployment info section, but the problem is that the app starts in an iPad-sized window that cannot be resized to a smaller size by user.

I would like to

  • allow the window to be resized to a smaller than default size
  • start the app with a smaller window size (that looks like iPhone app running in a window)

I tried adding frame modifier to ContentView like this, but it didn't accomplish anything:

import SwiftUI

@main
struct MyApp: App {
    @Environment(\.scenePhase) var scenePhase

    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    @StateObject var appState = AppState()

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(appState)
                // this is an attempt to start the app at 'iPhone-like' size
                .frame(minWidth: 320, idealWidth: 400, maxWidth: .infinity, minHeight: 480, idealHeight: 480, maxHeight: .infinity)
        }
    }
}

Here are project settings: enter image description here

2
  • Maybe this question gives you some ideas? Commented Aug 16, 2021 at 14:40
  • @AlejandroIván I've seen this, the second, newer answer (setting a frame on contentview) doesn't do anything for me. I'll see if the first one would help, but really, I'd rather not invoke NSWindow from SwiftUI unless absolutely needed ... Commented Aug 17, 2021 at 17:19

1 Answer 1

0

I had the same problem. I originally wrote it for macOS, then decided to write it for both. Ran perfectly on iOS but couldn’t resize for macOS. I had an example program that worked both for iOS and macOS but COULD resize on macOS. SO I copied Info items until it worked on macOS. Why? Some things on Xcode are a mystery. lol

But it works, so there you go.

I tried Supported iPhone interface orientation then Application Scene Manifest, then Launch Screen (you have to type in UILaunchScreen by hand). The last one is what made it work. However, it may need all three (shrug).

Using Xcode 15.4

NOTE: You must have Portrait AND Upside Down in General set or it doesn’t allow you to resize the macOS view. (Even though it says iPad Orientation)

enter image description here

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

Comments

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.