Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Support of graphView in UIScrollView
Browse files Browse the repository at this point in the history
Thank you to @nmattisson for this addition to the graph. See issue #12.
  • Loading branch information
Boris-Em committed Apr 20, 2014
1 parent bfb7467 commit 4745883
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions Classes/BEMSimpleLineGraphView.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ @interface BEMSimpleLineGraphView () {
/// The animation delegate for lines and dots
@property (strong, nonatomic) BEMAnimations *animationDelegate;

/// View for picking up pan gesture
@property (strong, nonatomic, readwrite) UIView *panView;

/// The gesture recognizer picking up the pan in the graph view
@property (strong, nonatomic) UIPanGestureRecognizer *panGesture;

/// Find which dot is currently the closest to the vertical line
- (BEMCircle *)closestDotFromVerticalLine:(UIView *)verticalLine;

Expand Down Expand Up @@ -144,14 +150,14 @@ - (void)layoutSubviews {
self.verticalLine.alpha = 0;
[self addSubview:self.verticalLine];

UIView *panView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, self.viewForBaselineLayout.frame.size.width, self.viewForBaselineLayout.frame.size.height)];
panView.backgroundColor = [UIColor clearColor];
[self.viewForBaselineLayout addSubview:panView];
self.panView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, self.viewForBaselineLayout.frame.size.width, self.viewForBaselineLayout.frame.size.height)];
self.panView.backgroundColor = [UIColor clearColor];
[self.viewForBaselineLayout addSubview:self.panView];

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
panGesture.delegate = self;
[panGesture setMaximumNumberOfTouches:1];
[panView addGestureRecognizer:panGesture];
self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
self.panGesture.delegate = self;
[self.panGesture setMaximumNumberOfTouches:1];
[self.panView addGestureRecognizer:self.panGesture];
}

// Let the delegate know that the graph finished layout updates
Expand Down Expand Up @@ -496,6 +502,19 @@ - (NSArray *)graphValuesForDataPoints {

#pragma mark - Touch Gestures

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isEqual:self.panGesture]) {
if (gestureRecognizer.numberOfTouches > 0) {
CGPoint translation = [self.panGesture velocityInView:self.panView];
return fabs(translation.y) < fabs(translation.x);
} else {
NSLog(@"yo");
return NO;
}
}
return YES;
}

- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer locationInView:self.viewForBaselineLayout];

Expand Down
Binary file not shown.

0 comments on commit 4745883

Please sign in to comment.