Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ee46a30

Browse files
committed
MotionGraphs: Version 2.0, 2017年02月02日
Updated to Swift This sample demonstrates how to receive updates from sensors using Core Motion. It displays graphs of accelerometer, gyroscope and device motion data. Signed-off-by: Liu Lantao <liulantao@gmail.com>
1 parent 9c23c37 commit ee46a30

34 files changed

+2142
-0
lines changed

‎MotionGraphs/LICENSE.txt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Sample code project: MotionGraphs
2+
Version: 2.0
3+
4+
IMPORTANT: This Apple software is supplied to you by Apple
5+
Inc. ("Apple") in consideration of your agreement to the following
6+
terms, and your use, installation, modification or redistribution of
7+
this Apple software constitutes acceptance of these terms. If you do
8+
not agree with these terms, please do not use, install, modify or
9+
redistribute this Apple software.
10+
11+
In consideration of your agreement to abide by the following terms, and
12+
subject to these terms, Apple grants you a personal, non-exclusive
13+
license, under Apple's copyrights in this original Apple software (the
14+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
15+
Software, with or without modifications, in source and/or binary forms;
16+
provided that if you redistribute the Apple Software in its entirety and
17+
without modifications, you must retain this notice and the following
18+
text and disclaimers in all such redistributions of the Apple Software.
19+
Neither the name, trademarks, service marks or logos of Apple Inc. may
20+
be used to endorse or promote products derived from the Apple Software
21+
without specific prior written permission from Apple. Except as
22+
expressly stated in this notice, no other rights or licenses, express or
23+
implied, are granted by Apple herein, including but not limited to any
24+
patent rights that may be infringed by your derivative works or by other
25+
works in which the Apple Software may be incorporated.
26+
27+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
28+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
29+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
30+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
31+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
32+
33+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
34+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
37+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
38+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
39+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
40+
POSSIBILITY OF SUCH DAMAGE.
41+
42+
Copyright (C) 2016 Apple Inc. All Rights Reserved.

‎MotionGraphs/MotionGraphs.xcodeproj/project.pbxproj‎

Lines changed: 345 additions & 0 deletions
Large diffs are not rendered by default.

‎MotionGraphs/MotionGraphs.xcodeproj/project.xcworkspace/contents.xcworkspacedata‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
</Bucket>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0820"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "B579FE3E1DDD1D2700A8C0C7"
18+
BuildableName = "MotionGraphs.app"
19+
BlueprintName = "MotionGraphs"
20+
ReferencedContainer = "container:MotionGraphs.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "B579FE3E1DDD1D2700A8C0C7"
36+
BuildableName = "MotionGraphs.app"
37+
BlueprintName = "MotionGraphs"
38+
ReferencedContainer = "container:MotionGraphs.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
<AdditionalOptions>
42+
</AdditionalOptions>
43+
</TestAction>
44+
<LaunchAction
45+
buildConfiguration = "Debug"
46+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48+
launchStyle = "0"
49+
useCustomWorkingDirectory = "NO"
50+
ignoresPersistentStateOnLaunch = "NO"
51+
debugDocumentVersioning = "YES"
52+
debugServiceExtension = "internal"
53+
allowLocationSimulation = "YES">
54+
<BuildableProductRunnable
55+
runnableDebuggingMode = "0">
56+
<BuildableReference
57+
BuildableIdentifier = "primary"
58+
BlueprintIdentifier = "B579FE3E1DDD1D2700A8C0C7"
59+
BuildableName = "MotionGraphs.app"
60+
BlueprintName = "MotionGraphs"
61+
ReferencedContainer = "container:MotionGraphs.xcodeproj">
62+
</BuildableReference>
63+
</BuildableProductRunnable>
64+
<AdditionalOptions>
65+
</AdditionalOptions>
66+
</LaunchAction>
67+
<ProfileAction
68+
buildConfiguration = "Release"
69+
shouldUseLaunchSchemeArgsEnv = "YES"
70+
savedToolIdentifier = ""
71+
useCustomWorkingDirectory = "NO"
72+
debugDocumentVersioning = "YES">
73+
<BuildableProductRunnable
74+
runnableDebuggingMode = "0">
75+
<BuildableReference
76+
BuildableIdentifier = "primary"
77+
BlueprintIdentifier = "B579FE3E1DDD1D2700A8C0C7"
78+
BuildableName = "MotionGraphs.app"
79+
BlueprintName = "MotionGraphs"
80+
ReferencedContainer = "container:MotionGraphs.xcodeproj">
81+
</BuildableReference>
82+
</BuildableProductRunnable>
83+
</ProfileAction>
84+
<AnalyzeAction
85+
buildConfiguration = "Debug">
86+
</AnalyzeAction>
87+
<ArchiveAction
88+
buildConfiguration = "Release"
89+
revealArchiveInOrganizer = "YES">
90+
</ArchiveAction>
91+
</Scheme>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>MotionGraphs.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>B579FE3E1DDD1D2700A8C0C7</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright (C) 2016 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
Abstract:
6+
A view controller to display output from the accelerometer.
7+
*/
8+
9+
import UIKit
10+
import CoreMotion
11+
import simd
12+
13+
class AccelerometerViewController: UIViewController, MotionGraphContainer {
14+
15+
// MARK: Properties
16+
17+
@IBOutlet weak var graphView: GraphView!
18+
19+
// MARK: MotionGraphContainer properties
20+
21+
var motionManager: CMMotionManager?
22+
23+
@IBOutlet weak var updateIntervalLabel: UILabel!
24+
25+
@IBOutlet weak var updateIntervalSlider: UISlider!
26+
27+
let updateIntervalFormatter = MeasurementFormatter()
28+
29+
@IBOutlet var valueLabels: [UILabel]!
30+
31+
// MARK: UIViewController overrides
32+
33+
override func viewWillAppear(_ animated: Bool) {
34+
super.viewWillAppear(animated)
35+
36+
startUpdates()
37+
}
38+
39+
override func viewDidDisappear(_ animated: Bool) {
40+
super.viewDidDisappear(animated)
41+
42+
stopUpdates()
43+
}
44+
45+
// MARK: Interface Builder actions
46+
47+
@IBAction func intervalSliderChanged(_ sender: UISlider) {
48+
startUpdates()
49+
}
50+
51+
// MARK: MotionGraphContainer implementation
52+
53+
func startUpdates() {
54+
guard let motionManager = motionManager, motionManager.isAccelerometerAvailable else { return }
55+
56+
updateIntervalLabel.text = formattedUpdateInterval
57+
58+
motionManager.accelerometerUpdateInterval = TimeInterval(updateIntervalSlider.value)
59+
motionManager.showsDeviceMovementDisplay = true
60+
61+
motionManager.startAccelerometerUpdates(to: .main) { accelerometerData, error in
62+
guard let accelerometerData = accelerometerData else { return }
63+
64+
let acceleration: double3 = [accelerometerData.acceleration.x, accelerometerData.acceleration.y, accelerometerData.acceleration.z]
65+
self.graphView.add(acceleration)
66+
self.setValueLabels(xyz: acceleration)
67+
}
68+
}
69+
70+
func stopUpdates() {
71+
guard let motionManager = motionManager, motionManager.isAccelerometerAvailable else { return }
72+
73+
motionManager.stopAccelerometerUpdates()
74+
}
75+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright (C) 2016 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
Abstract:
6+
The application delegate.
7+
*/
8+
9+
import UIKit
10+
import CoreMotion
11+
12+
@UIApplicationMain
13+
class AppDelegate: UIResponder, UIApplicationDelegate {
14+
15+
var window: UIWindow?
16+
17+
let motionManager = CMMotionManager()
18+
19+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
20+
// Enumerate through the view controller hierarchy, setting the `motionManager`
21+
// property on those that conform to the `MotionGraphContainer` protocol.
22+
window?.rootViewController?.enumerateHierarchy { viewController in
23+
guard var container = viewController as? MotionGraphContainer else { return }
24+
container.motionManager = motionManager
25+
}
26+
27+
return true
28+
}
29+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "29x29",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "29x29",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "40x40",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "40x40",
31+
"scale" : "3x"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"size" : "60x60",
36+
"scale" : "2x"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"size" : "60x60",
41+
"scale" : "3x"
42+
}
43+
],
44+
"info" : {
45+
"version" : 1,
46+
"author" : "xcode"
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /