SciChart iOS allows you to define custom grips for editable annotations by overriding the resizing grip drawing and hit-test logic. This enables complete control over the appearance and behavior of grips (the draggable handles used to resize annotations).
class customGripBoxAnnotation: SCIBoxAnnotation {
// Override to draw custom resizing grips
override func internalDrawResizingGrips(on context: CGContext, in rect: CGRect, at coordinates: SCIAnnotationCoordinates) {
let center = (coordinates.pt1.y + coordinates.pt2.y) / 2
drawCustomGrip(context: context, origin: CGPoint(x: coordinates.pt1.x, y: center))
}
// Draws the custom grip
private func drawCustomGrip(context: CGContext, origin: CGPoint) {
guard let context = UIGraphicsGetCurrentContext() else { return }
self.resizingGrip.onDrawCustomGrip(at: context, imgGrip: UIImage(named: “chart.modifier.zoomextents”) ?? UIImage(), isHorizontal: true, draw: CGRect(x: origin.x - 10, y: origin.y - 10, width: 20, height: 20))
}
}
Step 2: Handling Grip Interaction
Implement the getResizingGripHitIndex method to detect when a user taps or drags a custom grip. Return a valid SCIAnnotationPointIndex to indicate which grip is being interacted with.
// Override to detect hit on custom grip
- (SCIAnnotationPointIndex)getResizingGripHitIndexAt:(CGPoint)hitPoint
andAnnotationCoordinates:(SCIAnnotationCoordinates *)annotationCoordinates {
double center = (annotationCoordinates.pt1.y + annotationCoordinates.pt2.y) / 2.0;
CGRect gripFrame = CGRectMake(annotationCoordinates.pt1.x - 10, center - 10, 20, 20);
BOOL isHit = [self.resizingGrip customGripIsHitAtPoint:hitPoint andDrawnFrame:gripFrame];
if (isHit) {
return SCIAnnotationPointIndexX1Y1Index;
}
return -1;
}
// Override to detect hit on custom grip
override func getResizingGripHitIndex(at hitPoint: CGPoint, andAnnotationCoordinates annotationCoordinates: SCIAnnotationCoordinates) -> SCIAnnotationPointIndex {
let centerY = (annotationCoordinates.pt1.y + annotationCoordinates.pt2.y) / 2
let gripFrame = CGRect(x: annotationCoordinates.pt1.x - 10, y: centerY - 10, width: 20, height: 20)
let isHit = self.resizingGrip.customGripIsHit(at: hitPoint, andDrawnFrame: gripFrame)
return isHit ? SCIAnnotationPointIndex(rawValue: 0) : SCIAnnotationPointIndex(rawValue: -1)
}
You can define multiple grip positions and return different index values for each.