An open API service indexing awesome lists of open source software.

https://github.com/amerhukic/orientationtracker

Track device orientation changes even for devices with orientation-lock turned on.
https://github.com/amerhukic/orientationtracker

device-orientation ios orientation-detection orientation-tracking swift

Last synced: 3 months ago
JSON representation

Track device orientation changes even for devices with orientation-lock turned on.

Awesome Lists containing this project

README

          


Logo




Pod Version


License


Twitter: @hukicamer

**OrientationTracker** is a Core Motion based library for tracking device orientation changes. It also works for devices with orientation-lock turned on. You can subscribe to orientation change notifications and react accordingly.

## Requirements

- iOS 8.0+
- Xcode 10.2
- Swift 5.0

## Usage

To start device orientation tracking use `OrientationTracker` you simply invoke the `startDeviceOrientationTracking` method, preferably in `AppDelegate` :
```swift
DeviceOrientationDetector.shared.startDeviceOrientationTracking()
```

You then add an observer for the `OrientationTracker.deviceOrientationChangedNotification` and react to orientation changes:
```swift
NotificationCenter.default.addObserver(self, selector: #selector(updateViews), name: DeviceOrientationDetector.deviceOrientationChangedNotification, object: nil)
```

You can access the current orientation using the `currentDeviceOrientation` property.

To stop receiving notifications use the `stopDeviceOrientationTracking` method:
```swift
DeviceOrientationDetector.shared.stopDeviceOrientationTracking()
```

If your app supports portrait mode only, you can use the `affineTransform` property to rotate views when the orientation changes:
```swift
UIView.animate(withDuration: 0.2) {
self.imageView.transform = DeviceOrientationDetector.shared.affineTransform
}
```

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.

## Installation

### CocoaPods

[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:

```bash
$ gem install cocoapods
```

To integrate OrientationTracker into your Xcode project using CocoaPods, specify it in your `Podfile`:

```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '' do
pod 'OrientationTracker'
end
```

Then, run the following command:

```bash
$ pod install
```

## Author

[Amer Hukić](https://amerhukic.com)

## License

OrientationTracker is licensed under the MIT license. Check the [LICENSE](LICENSE) file for details.