I have started using this great SVGKit
for iOS. I am using a subclass of SVGKImageView
. Now before subclassing SVGKImageView
i have been easily able to add a UITapGestureRecognizer
to it. But my requirement made me to use subclasses as i have to place tens of SVGKImageView
on to my parent view.
(This is because there would be SVGKImageView
transparent portions on other views and i want to be able to ignore touches on the views areas where alpha = 0 so i want to be able to detect touch on a single SVGKImageView
then check for alpha value and if touch is on transparent area forward the touch event to the next view and so on until non transparent area of some view found)
Now after subclassing the SVGKImageView
adding UITapGestureRecognizer
does not work, also this
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
is not called in my subclass. I have also set SVGKImageView's userInteractionEnabled
to YES but of no avail.
Can anyone help tell me that why there is no touch/tap event being passed to my
SVGKImageView
subclass?
Below is my subclass init
method
- (instancetype)init{
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(svgImageTapped:)];
self.tapGestureRecognizer.numberOfTapsRequired = 1;
self.tapGestureRecognizer.delegate = self;
[self addGestureRecognizer:self.tapGestureRecognizer];
self.imageSVG = [SVGKImage imageNamed:@"SomeFile.svg"];
self = (Subclass*)[[SVGKLayeredImageView alloc] initWithSVGKImage:self.imageSVG];
[self sizeToFit];
self.userInteractionEnabled = YES;
self = [super init];
return self;
}
Let order your code: