forked from danielniemeyer/DNTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNViewController.m
More file actions
127 lines (100 loc) · 3.54 KB
/
DNViewController.m
File metadata and controls
127 lines (100 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// DNViewController.m
// DNTutorial
//
// Created by Daniel Niemeyer on 7/24/14.
// Copyright (c) 2014 Daniel Niemeyer. All rights reserved.
//
#import "DNViewController.h"
#import "DNTutorial.h"
@interface DNViewController ()
{
BOOL isMovingSquare;
}
@property (nonatomic, strong) CMMotionManager *motionManager;
@end
@implementation DNViewController
#pragma mark --
#pragma mark Initialization
#pragma mark --
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.imageView.image = [UIImage imageNamed:@"backgroundImage"];
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.accelerometerUpdateInterval = 0.2f;
self.motionManager.gyroUpdateInterval = 0.2f;
[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
[self outputAccelerometerData:accelerometerData.acceleration];
if (error)
{
NSLog(@"DNTutorialMovement: Accelerometer queue error: %@", error);
}
}];
[self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMGyroData *gyroData, NSError *error) {
[self outputRotationData:gyroData.rotationRate];
}];
}
- (void)viewDidDisappear:(BOOL)animated
{
[self.motionManager stopAccelerometerUpdates];
[self.motionManager stopGyroUpdates];
self.motionManager = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
// [DNTutorial advanceTutorialSequenceWithName:@"example"];
}
#pragma mark --
#pragma mark Private Methods
#pragma mark --
- (IBAction)investButtonAction:(id)sender
{
[DNTutorial completedStepForKey:@"secondStep"];
}
- (IBAction)dismissTutorial:(id)sender
{
[DNTutorial hideTutorial];
}
- (IBAction)showTutorial:(id)sender
{
[DNTutorial showTutorial];
}
- (IBAction)resetAction:(id)sender
{
[DNTutorial resetProgress];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [(UITouch *)[touches anyObject] locationInView:self.view];
[DNTutorial touchesBegan:touchPoint inView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [(UITouch *)[touches anyObject] locationInView:self.view];
[DNTutorial touchesMoved:touchPoint destinationSize:CGSizeMake(0, -100)];
self.square.center = touchPoint;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [(UITouch *)[touches anyObject] locationInView:self.view];
[DNTutorial touchesEnded:touchPoint destinationSize:CGSizeMake(0, -100)];
}
- (void)outputAccelerometerData:(CMAcceleration)acceleration;
{
}
- (void)outputRotationData:(CMRotationRate)rotation;
{
CGFloat centerX = self.view.center.x + 50*rotation.y;
CGFloat centerY = self.view.center.y + 50*rotation.x;
CGPoint center = CGPointMake(centerX, centerY);
[UIView animateWithDuration:0.24f animations:^{
self.imageView.center = center;
}];
}
@end