Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9292655de8 |
@@ -69,6 +69,15 @@ typedef NS_ENUM(NSInteger, JBChartViewState){
|
||||
@property (nonatomic, weak) id<JBChartViewDataSource> dataSource;
|
||||
@property (nonatomic, weak) id<JBChartViewDelegate> delegate;
|
||||
|
||||
/*
|
||||
* Since loading is such a common UIView requirement,
|
||||
* setting to YES will snapshot the chart, blur it, and display a loading indicator.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL loading;
|
||||
|
||||
- (void)setLoading:(BOOL)loading animated:(BOOL)animated callback:(void (^)())callback;
|
||||
- (void)setLoading:(BOOL)loading animated:(BOOL)animated;
|
||||
|
||||
/**
|
||||
* Header and footer views are shown above and below the chart respectively.
|
||||
* Each view will be stretched horizontally to fill width of chart.
|
||||
|
||||
+94
-79
@@ -14,16 +14,10 @@ CGFloat const kJBChartViewDefaultAnimationDuration = 0.25f;
|
||||
// Color (JBChartSelectionView)
|
||||
static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
|
||||
@interface JAPinchZoomView : UIView <UIScrollViewDelegate>
|
||||
|
||||
@property (nonatomic, strong) UIScrollView *scrollView;
|
||||
@property (nonatomic, strong) UIImageView *pinchZoomImageView;
|
||||
|
||||
@end
|
||||
|
||||
@interface JBChartView ()
|
||||
|
||||
@property (nonatomic, strong) JAPinchZoomView *pinchZoomView;
|
||||
@property (nonatomic, strong) UIImageView *loadingImageView;
|
||||
|
||||
@property (nonatomic, assign) BOOL hasMaximumValue;
|
||||
@property (nonatomic, assign) BOOL hasMinimumValue;
|
||||
|
||||
@@ -69,36 +63,6 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
- (void)constructChartView
|
||||
{
|
||||
self.clipsToBounds = YES;
|
||||
|
||||
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureRecognized:)];
|
||||
pinchGestureRecognizer.cancelsTouchesInView = NO;
|
||||
[self addGestureRecognizer:pinchGestureRecognizer];
|
||||
}
|
||||
|
||||
#pragma mark - Gestures
|
||||
|
||||
- (void)pinchGestureRecognized:(UIPinchGestureRecognizer *)pinchGestureRecognizer
|
||||
{
|
||||
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan)
|
||||
{
|
||||
for (UIView *subview in self.subviews)
|
||||
{
|
||||
//subview.hidden = YES;
|
||||
}
|
||||
|
||||
self.pinchZoomView = [[JAPinchZoomView alloc] init];
|
||||
self.pinchZoomView.pinchZoomImageView.image = [JBChartView imageWithView:self];
|
||||
self.pinchZoomView.frame = self.bounds;
|
||||
[self addSubview:self.pinchZoomView];
|
||||
}
|
||||
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded)
|
||||
{
|
||||
for (UIView *subview in self.subviews)
|
||||
{
|
||||
// subview.hidden = NO;
|
||||
}
|
||||
//[self.pinchZoomView removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
@@ -128,6 +92,98 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setLoading:(BOOL)loading animated:(BOOL)animated callback:(void (^)())callback
|
||||
{
|
||||
if (_loading == loading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_loading = loading;
|
||||
|
||||
if (loading) // show
|
||||
{
|
||||
UIImage *snapshotImage = [JBChartView imageWithView:self];
|
||||
self.loadingImageView = [[UIImageView alloc] initWithImage:snapshotImage];
|
||||
self.loadingImageView.frame = self.bounds;
|
||||
|
||||
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
||||
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blur];
|
||||
effectView.frame = self.loadingImageView.frame;
|
||||
[self.loadingImageView addSubview:effectView];
|
||||
|
||||
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||||
[activityIndicatorView startAnimating];
|
||||
activityIndicatorView.frame = CGRectMake(ceil(self.loadingImageView.frame.size.width * 0.5) - ceil(activityIndicatorView.frame.size.width * 0.5), ceil(self.loadingImageView.frame.size.height * 0.5) - ceil(activityIndicatorView.frame.size.height * 0.5), activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height);
|
||||
[self.loadingImageView addSubview:activityIndicatorView];
|
||||
|
||||
if (animated)
|
||||
{
|
||||
self.loadingImageView.alpha = 0.0;
|
||||
[self addSubview:self.loadingImageView];
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
self.loadingImageView.alpha = 1.0;
|
||||
} completion:^(BOOL finished) {
|
||||
if (callback)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self addSubview:self.loadingImageView];
|
||||
if (callback)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else // hide
|
||||
{
|
||||
if (self.loadingImageView != nil)
|
||||
{
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
self.loadingImageView.alpha = 0.0;
|
||||
} completion:^(BOOL finished) {
|
||||
[self.loadingImageView removeFromSuperview];
|
||||
if (callback)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.loadingImageView removeFromSuperview];
|
||||
if (callback)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setLoading:(BOOL)loading animated:(BOOL)animated
|
||||
{
|
||||
[self setLoading:loading animated:animated callback:nil];
|
||||
}
|
||||
|
||||
- (void)setLoading:(BOOL)loading
|
||||
{
|
||||
[self setLoading:loading animated:NO];
|
||||
}
|
||||
|
||||
- (void)setHeaderView:(UIView *)headerView
|
||||
{
|
||||
if (_headerView)
|
||||
@@ -282,44 +338,3 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation JAPinchZoomView
|
||||
|
||||
#pragma mark - Alloc/Init
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
_scrollView = [[UIScrollView alloc] init];
|
||||
_scrollView.delegate = self;
|
||||
_scrollView.minimumZoomScale = 1.0;
|
||||
_scrollView.maximumZoomScale = 6.0;
|
||||
[self addSubview:_scrollView];
|
||||
|
||||
_pinchZoomImageView = [[UIImageView alloc] init];
|
||||
[_scrollView addSubview:_pinchZoomImageView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Layout
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
self.scrollView.frame = self.bounds;
|
||||
self.pinchZoomImageView.frame = self.scrollView.bounds;
|
||||
}
|
||||
|
||||
#pragma mark - UIScrollViewDelegate
|
||||
|
||||
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
|
||||
{
|
||||
return self.pinchZoomImageView;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -305,15 +305,7 @@ NSString * const kJBLineChartViewControllerNavButtonViewKey = @"view";
|
||||
|
||||
- (void)chartToggleButtonPressed:(id)sender
|
||||
{
|
||||
UIView *buttonImageView = [self.navigationItem.rightBarButtonItem valueForKey:kJBLineChartViewControllerNavButtonViewKey];
|
||||
buttonImageView.userInteractionEnabled = NO;
|
||||
|
||||
CGAffineTransform transform = self.lineChartView.state == JBChartViewStateExpanded ? CGAffineTransformMakeRotation(M_PI) : CGAffineTransformMakeRotation(0);
|
||||
buttonImageView.transform = transform;
|
||||
|
||||
[self.lineChartView setState:self.lineChartView.state == JBChartViewStateExpanded ? JBChartViewStateCollapsed : JBChartViewStateExpanded animated:YES callback:^{
|
||||
buttonImageView.userInteractionEnabled = YES;
|
||||
}];
|
||||
[self.chartView setLoading:!self.chartView.loading animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Overrides
|
||||
|
||||
Reference in New Issue
Block a user