• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Core Motion in iOS using Swift

Core Motion in iOS using Swift

Users generate motion events when they move, shake, or tilt the device. These motion events are detected by the device hardware, specifically, the accelerometer and the gyroscope. The Core Motion framework lets your application receive motion data from the device hardware and process that data.

alt tag

To get started import the Core Motion framework like this:

import CoreMotion

Now create an instance of CMMotionManager object. The app can use it to receive four types of motion: raw accelerometer data, raw gyroscope data, raw magnetometer data, and processed device-motion data (which includes accelerometer, rotation-rate, and attitude measurements).

let motionManager = CMMotionManager()

For starting accelerometer updates you need to call the next method:

func startAccelerometerUpdates()

Finally, read the accelerometer data as often as you want.

if let accelerometerData = motionManager.accelerometerData {
}

You can change accelerometerUpdateInterval, the interval, in seconds, for providing accelerometer updates to the block handler.

The same story for Gyroscope, Magnetometer and Device motion.

func startGyroUpdates()
func startMagnetometerUpdates()
func startDeviceMotionUpdates()

Happy coding!

More Repositories

1

Language-Manager-iOS

Language Manager iOS
Objective-C
233
star
2

Mac-OS-X-App-Menu-Bar-Popup

Mac OS X Application like a menu bar popup message
Swift
183
star
3

Calendar-iOS

Calendar View
Objective-C
161
star
4

SwiftGoogleTranslate

Lightweight framework for using Cloud Translation API by Google
Swift
86
star
5

SwiftAssetsPickerController

A simple assets picker controller based on iOS 8 Photos framework. Supports iCloud photos and videos. It's written in Swift.
Swift
85
star
6

Swift-Amazon-S3-Uploading-Tutorial

How to upload a file to Amazon S3 using Swift
Swift
76
star
7

UICollectionViewHorizontalPaging

iOS UICollectionView Page Scrolling
Swift
71
star
8

iOS-Crosswords-Generator

A simple algorithm for generating crosswords written on Swift. Based on Python Crossword Puzzle Generator.
Swift
52
star
9

iOS-Shared-CoreData-Storage-for-App-Groups

iOS Shared CoreData Storage for App Groups
Swift
49
star
10

SwiftHUEColorPicker

iOS HUE color picker
Swift
46
star
11

iOS-Swift-Drawing-App

Swift Drawing Application Sample
Swift
40
star
12

iOS-AirDrop-Custom-Data

iOS Airdrop Custom Data Transferring Example
Objective-C
38
star
13

CheckMarkView

UI view which draws programmatically a checkmark with different styles
Swift
35
star
14

iOS-Swift-In-App-Purchases-Sample

iOS Swift In-App-Purchases Sample
Swift
33
star
15

SKTextureGradient

A SpriteKit SKTexture Gradient
Swift
29
star
16

iOS-MapKit-Tutorial

iOS MapKit Getting Started
Swift
26
star
17

iOS-MySQL-Client

iOS MySQL client
Objective-C
26
star
18

iOS-Today-Extension-Simple-Tutorial

iOS Today Extension Simple Tutorial
Swift
25
star
19

Quizlet-iOS

iOS framework for using Quizlet API 2.0
Objective-C
18
star
20

UIAlertController-Customization

Customization of UIAlertController
Swift
18
star
21

JobsFinder

A script which parses Upwork RSS feed and sends notifications to Telegram
JavaScript
17
star
22

SwiftlySlider

A simple iOS slider control
Swift
14
star
23

iOS-Heart-Rate-Monitor

iOS Heart Rate Monitor
Objective-C
12
star
24

SignalStrengthIndicator

Signal Strength Indicator
Swift
11
star
25

iOS-Dragon-Mobile-SDK-Example

Nuance Dragon Mobile SDK and ObjectAL
HTML
10
star
26

MBFileDownloader

A file downloader.
Objective-C
9
star
27

The-Pursuit-Demo

3D racing with physics powered by Marmalade SDK and Bullet Physics
GLSL
9
star
28

iOS-UIImage-render-to-PDF

iOS Render UIImage to PDF and merging PDF files
Objective-C
9
star
29

iOS-Pie-Chart

iOS Pie Chart
Objective-C
9
star
30

SwiftlyScrollSlider

A custom scroll slider for UIScrollView
Swift
8
star
31

3D-Touch-Quick-Actions-Demo

iOS 3D Touch: How to add quick actions
Swift
8
star
32

iOS-YouTube-Browser

iOS YouTube Browser Sample
Objective-C
8
star
33

iOS-Swift-ObjC-Mix

An example of the mixing Swift and Obj C code in the same project
Objective-C
7
star
34

SwiftThicknessPicker

iOS thickness picker
Swift
6
star
35

iOS-Document-Iteraction

iOS: How to copy epub files from your app to iBooks app
Swift
6
star
36

iOS-Tag-List

iOS Tag List
Objective-C
6
star
37

SwiftTintedButtonExtension

A small Swift extension for tinting UIButton, like a UIBarButtonItem or a UINavigationItem
Swift
5
star
38

iOS-QuickBlox-File-Uploader-Downloader

Quickblox: Uploading from a file, downloading to a file
Objective-C
4
star
39

UIStripedView

A striped view
Objective-C
3
star
40

WaitSpinner

Very very simple activity indicator
Objective-C
3
star
41

iOS-Frequency-Table

iOS Frequency Table
Objective-C
3
star
42

UITextViewPlaceholder

UITextView Placeholder Tutorial
Swift
3
star
43

UISegmentedControl_IconAndText

A simple category for adding icon and text together to default UISegmentedControl
Objective-C
3
star
44

UIColorRGBA

Provides a convenience UIColor method for set up a color from a HEX string in Swift.
Swift
2
star
45

SwiftyAccountKit

Facebook AccountKit wrapper
Swift
2
star
46

T-Block

T-Block
C++
1
star
47

SwiftOxfordAPI

A framework to use Oxford Dictionaries API written in Swift
Swift
1
star
48

Patchcord

The project represents an example of Redux architecture using SwiftUI + Combine + CoreData.
Swift
1
star
49

Locale-Alphabet

An example that shows how to take the current alphabet from the text
Objective-C
1
star
50

SwiftUI-WidgetKit-Gradient-Issue

This code shows a bug with gradient colors which is happening using Widgets extension for iOS 14
Swift
1
star
51

CIColorRGBA

Provides a convenience CIColor method for set up a color from a HEX string in Swift
Swift
1
star