开发者

Detecting Touch On UIView

开发者 https://www.devze.com 2023-02-18 11:12 出处:网络
Hello All I drawn Pie Chart on a UIView using CGContext of 10 Arcs (pieces or slice). But When I touch on the 1st arc and last arcof this piechart i dont get touch point from them..开发者_JAVA技巧.r

Hello All I drawn Pie Chart on a UIView using CGContext of 10 Arcs (pieces or slice).

But When I touch on the 1st arc and last arc of this piechart i dont get touch point from them..开发者_JAVA技巧.rest of all arcs of this piechart supports touch event....

why this is happening m stuck of that... please help me...to get out this...

here is my code

-(void) drawRect:(CGRect)rect
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextSetLineWidth(ctx, 2.0);

float mult = 360/total;
// Draw each pie slice   
float curValue = 0.0f;  

for(int i=0; i< 10; i++)
    {   
    int startAngle = (int)(curValue * mult);  
    int arcAngle = (int)  ([[sorted objectAtIndex:i] floatValue]* mult);   

    // Ensure that rounding errors do not leave a gap between the first and last slice   
    if ( count == [sorted count] ) { arcAngle = 360 - startAngle; }   

    CGContextBeginPath(ctx);  
    CGContextMoveToPoint(ctx, x, y );
    CGContextAddArc(ctx, x, y, r, startAngle * M_PI/180.0, (startAngle * M_PI/180.0) + (arcAngle * M_PI/180), 0);

    CGContextClosePath(ctx);  

    CGContextSetStrokeColorWithColor(ctx, [[UIColor lightGrayColor] CGColor]); 
    CGContextDrawPath(ctx, kCGPathFillStroke );  curValue += [[sorted objectAtIndex:i] floatValue];

    }  
}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
double startRotationValue = [[[self.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue];
rotation.fromValue = [NSNumber numberWithDouble:startRotationValue];
rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5];
rotation.duration = 2.0;
[self.layer addAnimation:rotation forKey:@"rotating"];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesBegan:touches withEvent:event];
}

Thanks in Advance.......

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号