diff --git a/LMGraphView/LMLineGraphView.h b/LMGraphView/LMLineGraphView.h index 7dc6200..edc620e 100755 --- a/LMGraphView/LMLineGraphView.h +++ b/LMGraphView/LMLineGraphView.h @@ -33,6 +33,8 @@ @property (nonatomic, weak) id delegate; +@property (nonatomic, assign, getter=shouldScrollToRecentData) BOOL scrollToRecentData; + - (void)animateWithDuration:(NSTimeInterval)duration; - (UIImage *)graphImage; diff --git a/LMGraphView/LMLineGraphView.m b/LMGraphView/LMLineGraphView.m index 9e99677..41fabe5 100755 --- a/LMGraphView/LMLineGraphView.m +++ b/LMGraphView/LMLineGraphView.m @@ -233,6 +233,14 @@ - (void)drawRect:(CGRect)rect // Draw plots [self drawPlots]; + + if(self.shouldScrollToRecentData) { + ///Scroll to most recent data + CGSize contentScrollViewSize = self.contentScrollView.contentSize; + if(contentScrollViewSize.width > W(self.contentScrollView)) { + [self.contentScrollView scrollRectToVisible:CGRectMake(contentScrollViewSize.width - W(self.contentScrollView), self.contentScrollView.contentOffset.y, contentScrollViewSize.width, contentScrollViewSize.height) animated:YES]; + } + } } else {