Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason for - (void)cancelTrackingWithEvent:(UIEvent *)event getting called If I am using MSSlideNavigationController?

Tags:

ios

uicontrol

I tried to use custom UIControl in my view controller. My custom class which subclasses the UIControl and allocate the instance for my custom control and adding in to my view controller's view by following code

 CustomControl *customControl = [[CustomControl alloc]initWithFrame:CGRectMake(44, 388, 235, 160)];
 [self.view addSubview:customControl];

Then I am implementing the following delegate methods in CustomControl

- (BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (void) endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)cancelTrackingWithEvent:(UIEvent *)event

The problem I am facing is when I am tracking inside the control -(void)cancelTrackingWithEvent:(UIEvent *)event get called after that - (BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event method doesn't get called. So why this method - (void)cancelTrackingWithEvent:(UIEvent *)event getting called...

I read the document that says, // event may be nil if cancelled for non-event reasons, e.g. removed from window but can't understand the exact scernario Thanks in advance.

Always I return YES only. The delegates I have implemented are:

- (BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
    [super beginTrackingWithTouch:touch withEvent:event];
    NSLog(@"Touch begins");
    return YES;
}

- (BOOL) continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
    [super continueTrackingWithTouch:touch withEvent:event];
    NSLog(@"Touch continous");
    return YES;
}

- (void) endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
    [super endTrackingWithTouch:touch withEvent:event];
    NSLog(@"Touch ends");
}

- (void)cancelTrackingWithEvent:(UIEvent *)event
{
    NSLog(@"Touch cancelled due to remove from window");
}
like image 738
jailani Avatar asked Jan 23 '14 04:01

jailani


1 Answers

I found out the problem. I used MSSlideNavigationController which overrides - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

So when I track, the touch passed to MSSlideNavigationController. To solve this I changed the (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch' inMSSlideNavigationController` class that returns NO when the tracking comes from my CustomUIControl. I set tag 9999 to my customcontrol

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    if (touch.view.tag == 9999) {
        return NO;
    }
    return YES;
}
like image 120
jailani Avatar answered Oct 24 '22 13:10

jailani