I need to add gesture recognizer to the center of Pie Chart
Here I read that it's possible to add my gesture rec to the HostView. I used next:
UILongPressGestureRecognizer *longPressGesture = [[[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(centerBtnDblPrsd)]
autorelease];
[longPressGesture setMinimumPressDuration:1];
[self.hostView addGestureRecognizer:longPressGesture];
(I've add to .h file)
But this doesnt work, how can I add gesture rec to the hostView?
EDIT: My code for CorePlot:
-(void)configureHost {
// 1 - Set up view frame
CGRect parentRect = self.firstPieChartView.bounds;
//CGSize toolbarSize = self.myPieChartPlaceholder.bounds.size;
parentRect = CGRectMake(0, 80,
parentRect.size.width,
parentRect.size.height);
// 2 - Create host view
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:parentRect];
self.hostView.allowPinchScaling = YES;
self.hostView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.hostView];
}
-(void)configureGraph {
// 1 - Create and initialize graph
graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
self.hostView.hostedGraph = graph;
self.hostView.backgroundColor = [UIColor clearColor];
graph.paddingLeft = 0.0f;
graph.paddingTop = 0.0f;
graph.paddingRight = 0.0f;
graph.paddingBottom = 0.0f;
graph.axisSet = nil;
// 2 - Set up text style
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor grayColor];
textStyle.fontName = @"Helvetica-Thin";
textStyle.fontSize = 17.0f;
// 3 - Configure title
NSString *title = @""; //_infoLabel.text;
graph.title = title;
graph.titleTextStyle = textStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, -12.0f);
UIImage *img = [UIImage imageNamed:@"hostViewPlchldr.png"];
CPTImage *cptImg=[CPTImage imageWithCGImage:img.CGImage scale:img.scale*2];
graph.fill = [CPTFill fillWithImage:cptImg];
}
-(void)configureChart {
// 1 - Get reference to graph
graph = self.hostView.hostedGraph;
// 2 - Create chart
CPTPieChart *pieChart = [[CPTPieChart alloc] init];
CPTMutableLineStyle *line=[CPTMutableLineStyle lineStyle];
line.lineColor=[CPTColor grayColor];
line.lineWidth = 1.0;
pieChart.borderLineStyle = line;
//Положение надписей на секторах
pieChart.labelOffset = -30;
pieChart.dataSource = self;
pieChart.delegate = self;
pieChart.pieRadius = (self.hostView.bounds.size.height * 1.3) / 3;
pieChart.pieInnerRadius = 35.0;
pieChart.identifier = graph.title;
pieChart.startAngle = M_PI/2;
pieChart.sliceDirection = CPTPieDirectionClockwise;
// 3 - Create gradient
CPTGradient *overlayGradient = [[CPTGradient alloc] init];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.9];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.4] atPosition:1.0];
pieChart.overlayFill = [CPTFill fillWithGradient:overlayGradient];
// 4 - Add chart to graph
[graph addPlot:pieChart];
}
-(void)viewDidLoad
{
_firstPieChartView.backgroundColor = [UIColor clearColor];
[super viewDidLoad];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap)];
[longPressGesture setMinimumPressDuration:1];
[self.hostView addGestureRecognizer:longPressGesture];
[self.hostView setUserInteractionEnabled:YES];
}
I too tested your code
-(void)viewDidLoad
{
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap)];
[longPressGesture setMinimumPressDuration:1];
[self.tempView addGestureRecognizer:longPressGesture];
[self.tempView setUserInteractionEnabled:YES];
}
-(void)longTap
{
NSLog(@"tapped");
}
my longTap method is getting called... If your stil not working ,you could provide more code so I could have more look in it for your issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.