{"id":19252216,"url":"https://github.com/bellapplab/orientation","last_synced_at":"2025-02-23T16:50:32.723Z","repository":{"id":62449696,"uuid":"46482760","full_name":"BellAppLab/Orientation","owner":"BellAppLab","description":"A Swifty way to deal with and normalize orientations on iOS.","archived":false,"fork":false,"pushed_at":"2017-06-17T05:58:46.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T10:50:44.916Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BellAppLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-19T09:44:03.000Z","updated_at":"2020-10-16T09:02:14.000Z","dependencies_parsed_at":"2022-11-01T23:17:59.131Z","dependency_job_id":null,"html_url":"https://github.com/BellAppLab/Orientation","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FOrientation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FOrientation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FOrientation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FOrientation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BellAppLab","download_url":"https://codeload.github.com/BellAppLab/Orientation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240347928,"owners_count":19787236,"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":[],"created_at":"2024-11-09T18:25:53.670Z","updated_at":"2025-02-23T16:50:32.682Z","avatar_url":"https://github.com/BellAppLab.png","language":"Swift","readme":"# Orientation\n\nA Swifty way to deal with and normalize orientations on iOS.\n\n_v0.4.0_\n\n## Usage\n\nAccording to the docs on `UIDevice.currentDevice().orientation`:\n\n\u003eThe value of this property always returns 0 unless orientation notifications have been enabled by calling `beginGeneratingDeviceOrientationNotifications`.\n\nAlso, calling `endGeneratingDeviceOrientationNotifications` seems to be a good idea, to preserve batery life.\n\nThus, this library not only normalizes the various types of orientations iOS works with (`UIDeviceOrientation`, `UIInterfaceOrientation`, `UIImageOrientation` and optionally `AVCaptureVideoOrientation`), but also attempts to optimize the generation of such rotation notifications by creating a shared weak singleton that will only stay alive as long as there's an object needing it (ie. holding a strong reference to it) and that will end the generation of orientation notifications when it's deinit'ed.\n\n**Here's how to use it**:\n\n```swift\nclass ViewController: UIViewController {\n\n    let orientation = Orientation.shared()\n\n    override public func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {\n\n        /*\n            We need to call `check()`, because iOS only produces the `UIDeviceOrientationDidChangeNotification` and not its `UIDeviceOrientationWillChangeNotification` counterpart. So the current orientation will only by updated automatically when the rotation finishes.\n            How is this better than checking for `UIDevice.currentDevice().orientation`? Because if the device moves from `UIDeviceOrientationPortrait` to `UIDeviceOrientationFaceUp`, we maintain it as `UIDeviceOrientationPortrait`. After all, your UI doesn't really need to change when the device is sitting on its back, does it?\n            Also, you may simply disregard `UIInterfaceOrientation`. Neat, huh?\n        */\n        let currentOrientation = self.orientation.check()\n\n        switch currentOrientation \n        {\n            case .Portrait: //do something if we are portrait\n            default: //else case\n        }\n\n        coordinator.notifyWhenInteractionEndsUsingBlock { [unowned self] (ctx: UIViewControllerTransitionCoordinatorContext) -\u003e Void in\n            if !ctx.isInteractive() {\n                //no need to call check, because now it's been checked automatically\n                let currentOrientation = self.orientation.current \n                /* ... */\n            }\n        }\n\n        super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)\n    }\n}\n```\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n* iOS 8+\n* Swift 3.0\n\n## Installation\n\n### Cocoapods\n\nBecause of [this](http://stackoverflow.com/questions/39637123/cocoapods-app-xcworkspace-does-not-exists), I've dropped support for Cocoapods on this repo. I cannot have production code rely on a dependency manager that breaks this badly. \n\n### Git Submodules\n\n**Why submodules, you ask?**\n\nFollowing [this thread](http://stackoverflow.com/questions/31080284/adding-several-pods-increases-ios-app-launch-time-by-10-seconds#31573908) and other similar to it, and given that Cocoapods only works with Swift by adding the use_frameworks! directive, there's a strong case for not bloating the app up with too many frameworks. Although git submodules are a bit trickier to work with, the burden of adding dependencies should weigh on the developer, not on the user. :wink:\n\nTo install Orientation using git submodules:\n\n```\ncd toYourProjectsFolder\ngit submodule add -b submodule --name Orientation https://github.com/BellAppLab/Orientation.git\n```\n\nNavigate to the new Orientation folder and drag the `Source` folder to your Xcode project.\n\n**Note: ** If you're not using `AVFoundation` on your project, just remove the reference to the `Video` folder.\n\n## Author\n\nBell App Lab, apps@bellapplab.com\n\n## License\n\nOrientation is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Forientation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbellapplab%2Forientation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Forientation/lists"}