-
Notifications
You must be signed in to change notification settings - Fork 1
/
ViewController.m
83 lines (67 loc) · 2.84 KB
/
ViewController.m
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
//
// ViewController.m
// ForceTouchGestureRecognizerExample
//
// Created by Yu Sugawara on 9/25/15.
// Copyright © 2015 Yu Sugawara. All rights reserved.
//
#import "ViewController.h"
#import "ForceTouchGestureRecognizer.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *tapView;
@property (strong, nonatomic) IBOutlet ForceTouchGestureRecognizer *forceTouchGestureRecognizer;
@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *singleTapGestureRecognizer;
@property (strong, nonatomic) IBOutlet UITapGestureRecognizer *doubleTapGestureRecognizer;
@property (strong, nonatomic) IBOutlet UILongPressGestureRecognizer *longPressGestureRecognizer;
@property (weak, nonatomic) IBOutlet UILabel *gestureLabel;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self.forceTouchGestureRecognizer addTarget:self action:@selector(viewForceTouched:)];
self.forceTouchGestureRecognizer.forceSensitivity = 0.5;
[self.singleTapGestureRecognizer addTarget:self action:@selector(viewSingleTapped:)];
[self.doubleTapGestureRecognizer addTarget:self action:@selector(viewDoubleTapped:)];
[self.longPressGestureRecognizer addTarget:self action:@selector(viewlongPressed:)];
[self.singleTapGestureRecognizer requireGestureRecognizerToFail:self.doubleTapGestureRecognizer];
}
- (void)viewForceTouched:(ForceTouchGestureRecognizer *)sender
{
[self updateGestureLabel:[NSString stringWithFormat:@"Force tapped, force = %f", sender.force]];
}
- (void)viewSingleTapped:(ForceTouchGestureRecognizer *)sender
{
[self updateGestureLabel:@"Single tapped"];
}
- (void)viewDoubleTapped:(ForceTouchGestureRecognizer *)sender
{
[self updateGestureLabel:@"Double tapped"];
}
- (void)viewlongPressed:(ForceTouchGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan) {
[self updateGestureLabel:@"Long pressed - began"];
} else if (sender.state == UIGestureRecognizerStateEnded) {
[self updateGestureLabel:@"Long pressed - Ended"];
}
}
- (void)updateGestureLabel:(NSString *)gestureString
{
NSLog(@"%@", gestureString);
self.gestureLabel.text = gestureString;
[UIView animateWithDuration:0.15
animations:^{
self.gestureLabel.alpha = 1.;
} completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.3
delay:1.
options:kNilOptions
animations:^{
self.gestureLabel.alpha = 0.;
} completion:nil];
}
}];
}
@end