{"id":19093070,"url":"https://github.com/ryanlintott/rotationmatchingorientation","last_synced_at":"2025-09-08T00:32:14.875Z","repository":{"id":115710376,"uuid":"495513579","full_name":"ryanlintott/RotationMatchingOrientation","owner":"ryanlintott","description":"Rotates any SwiftUI view to match device orientation","archived":false,"fork":false,"pushed_at":"2022-05-23T20:46:50.000Z","size":71,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-09T03:25:31.346Z","etag":null,"topics":["swiftui"],"latest_commit_sha":null,"homepage":"https://github.com/ryanlintott/FrameUp","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanlintott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-23T17:41:43.000Z","updated_at":"2024-05-24T14:58:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"16948fbe-476b-4a2f-ae15-e83b8b9e34ba","html_url":"https://github.com/ryanlintott/RotationMatchingOrientation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanlintott%2FRotationMatchingOrientation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanlintott%2FRotationMatchingOrientation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanlintott%2FRotationMatchingOrientation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanlintott%2FRotationMatchingOrientation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanlintott","download_url":"https://codeload.github.com/ryanlintott/RotationMatchingOrientation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232268307,"owners_count":18497346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swiftui"],"created_at":"2024-11-09T03:23:14.267Z","updated_at":"2025-01-02T23:22:44.446Z","avatar_url":"https://github.com/ryanlintott.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RotationMatchingOrientation\n\nRotates any view so that it matches the device orientation if it's in an array of allowed orientations.\n\n*Submission for SwiftUISeries - Workarounds \u0026 Hacks event*\n\n# Why did I make this workaround?\nWhen building [Old English Wordhord](https://oldenglishwordhord.com/app/) I wanted the app to be portrait-only but the image view to rotate with the phone. Although this can be done in UIKit, SwiftUI doesn't have a way to control allowed orientations per view.\n\n# Example\nThe app only allows portrait and landscapeLeft orientations but the content can be set to rotate to any number of orientations using the toggles.\n\n[![Example Video](https://img.youtube.com/vi/Ae4hbOIU9jc/0.jpg)](https://www.youtube.com/watch?v=Ae4hbOIU9jc)\n\n# How does it work?\n- Device orientation is taken from `UIDevice.current.orientation`\n- `supportedInterfaceOrientations` is taken from `UISupportedInterfaceOrientations` in the app bundle\n- `interfaceOrientation` is determined from `deviceOrientation` and `supportedInterfaceOrientations`\n- `contentOrientation` is determined from `deviceOrientation` and `allowedOrientations`\n- Rotation between `interfaceOrientation` and `contentOrientation` is used to rotate the content view\n- GeometryReader is used to calculate the size of the space\n- Height and width of the content are swapped if there's a 90 degree different between `interfaceOrientation` and `contentOrientation`\n- `.position()` modifier is used to center the view\n- Orientations are updated whenever:\n  - `.onAppear`\n  - `allowedOrientations` are changed\n  - `.orientationDidChangeNotification` fires\n  - `.willEnterForegroundNotification` fires\n\n# Use it in your app\nThis component is available in my Swift package:\n\n\u003ca href=\"https://github.com/ryanlintott/FrameUp\"\u003e\n  \u003cimg width=\"456\" alt=\"FrameUp Logo\" src=\"https://user-images.githubusercontent.com/2143656/149010960-2b0e1200-b6d4-40a5-bbe7-4aabc5ce6b09.png\"\u003e\n\u003c/a\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanlintott%2Frotationmatchingorientation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanlintott%2Frotationmatchingorientation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanlintott%2Frotationmatchingorientation/lists"}