Can't properly zoom & pan chart in UIScrollView

5 posts, 0 answers
  1. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 17 Dec 2014 Link to this post

    I added a TKChart to a UIScrollView, the scroll worked properly, but when I pinch/pan my chart it barely worked.

    Sometimes when i pinch the chart, it just shifting, and when i pan it, it zooming in/out. And sometimes the chart can't be zoomed/panned at all.

    When i put the chart outside UIScrollView, zoom & pan worked properly.

    How to solve this?
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Dec 2014 Link to this post

    Hello Muhammad,

    I have just tried to reproduce the problem I have placed a TKChart inside a UIScrollView . So far it seems to work as expected. 

    Can you please share any details ( e.g. code )  that might help reproduce the issue ? Once I am able to reproduce the problem I believe I can provide a solution  or a  workaround for you . 

    Regards,
    Pavel Pavlov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 18 Dec 2014 Link to this post

    This reproduce the problem:

    (btw why there's no Objective-C option in Format Code Block?)

    01.#import "ViewController.h"
    02.#import <TelerikUI/TelerikUI.h>
    03. 
    04.@interface ViewController ()
    05.@property (strong, nonatomic) UIScrollView *scrollView;
    06.@property (strong, nonatomic) TKChart *chart;
    07.@end
    08. 
    09.@implementation ViewController
    10. 
    11.- (void)viewDidLoad {
    12.    [super viewDidLoad];
    13.    // Do any additional setup after loading the view, typically from a nib.
    14.    // Adding scrollview
    15.    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, self.navigationController.navigationBar.frame.size.height, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
    16.    [self.scrollView setUserInteractionEnabled:YES];
    17.    [self.scrollView setBackgroundColor:[UIColor blackColor]];
    18.    [self.scrollView setContentSize:CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) + 1000)];
    19.    [self.view addSubview:self.scrollView];
    20.     
    21.    // Adding chart
    22.    self.chart = [[TKChart alloc] initWithFrame:CGRectInset(self.view.bounds, 150, 150)];
    23.    self.chart.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    24.    [self.scrollView addSubview:self.chart];
    25. 
    26.    // Set data
    27.    NSMutableArray *randomNumericData = [[NSMutableArray alloc] init];
    28.    for (int i = 0; i < 10; i++) {
    29.        [randomNumericData addObject:[[TKChartDataPoint alloc] initWithX:@(i) Y:@(arc4random()%100)]];
    30.    }
    31.     
    32.    [self.chart addSeries:[[TKChartLineSeries alloc] initWithItems:randomNumericData]];
    33.    self.chart.title.hidden = NO;
    34.    self.chart.title.text = @"Grafik yeah";
    35.    self.chart.legend.hidden = NO;
    36.    self.chart.allowAnimations = YES;
    37.    self.chart.xAxis.allowZoom = YES;
    38.}
      39.@end

    I think the problem's occured because when I pinch/swipe the chart, there's conflict between chart's gesture detector and scrollview's one. So maybe I must make each detector exclusive (how to do this?). Or is there any better solution?

    Sorry for my bad english btw
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 19 Dec 2014 Link to this post

    Hello Muhammad,

    Thanks for sharing the code. I have put it in a project  but I am afraid I still can not reproduce the issue.

    What I have done - I have pasted your code into a view controllers viewDidLoad method.
    I have just changed the size in the following line :

    self.chart = [[TKChart alloc] initWithFrame:CGRectMake(0,0,150,150)];


    as the chart was not displayed well.

    What I observed : 
    I could pinch zoom the chart and later pan it with no problem.

    Am I missing something , e.g some steps to reproduce the issue ? 
    Do you get it in a simulator or on a real device ( device version , iOS version).

    *I assume you are working with version 2014.3 1024 of our iOS controls suite.

    Regards,
    Pavel Pavlov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 13 Jan 2015 in reply to Pavel Pavlov Link to this post

    Hello Pavel,

    I updated the framework to the latest update, and it worked well. Thank you :)
Back to Top
DevCraft banner