blob: 6d1bd959b40e9fc58a3ec76412ce3679c067c584 (
plain)
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
|
//
// SDLPinchGesture.m
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//
#import "SDLPinchGesture.h"
#import "SDLTouch.h"
#import "CGPoint_Util.h"
@implementation SDLPinchGesture
@synthesize distance = _distance;
@synthesize center = _center;
- (instancetype)initWithFirstTouch:(SDLTouch*)firstTouch secondTouch:(SDLTouch*)secondTouch {
self = [super init];
if (!self) {
return nil;
}
_firstTouch = firstTouch;
_secondTouch = secondTouch;
_distance = -1;
_center = CGPointZero;
return self;
}
#pragma mark - Setters
- (void)setFirstTouch:(SDLTouch *)firstTouch {
if (firstTouch.identifier == SDLTouchIdentifierFirstFinger) {
_firstTouch = firstTouch;
[self sdl_invalidate];
}
}
- (void)setSecondTouch:(SDLTouch *)secondTouch {
if (secondTouch.identifier == SDLTouchIdentifierSecondFinger) {
_secondTouch = secondTouch;
[self sdl_invalidate];
}
}
#pragma mark - Getters
- (CGFloat)distance {
if (_distance == -1) {
_distance = CGPointDistanceBetweenPoints(self.firstTouch.location,
self.secondTouch.location);
}
return _distance;
}
- (CGPoint)center {
if (CGPointEqualToPoint(_center, CGPointZero)) {
_center = CGPointCenterOfPoints(self.firstTouch.location,
self.secondTouch.location);
}
return _center;
}
- (BOOL)isValid {
return (self.firstTouch != nil) && (self.secondTouch != nil);
}
#pragma mark - Private
- (void)sdl_invalidate {
_distance = -1;
_center = CGPointZero;
}
@end
|