I have a UIScrollView containing a UIView (blue grid), containing another UIView (orange bordered 'part'), containing the UISwitch (shown mid-run).
The blue grid can scroll around with the finger, and the part can also drag around. I implement this with a pan gesture recognizer. My main problem seems to be trying to get the swipe gesture of the switch to work properly.
Right now the tap to toggle works on the switch fine, and a short distance swipe on the switch works. But if you are doing a more involved (but non-the-less common) slow method to toggle the switch it will start to drag the part with the switch mid-toggle (this is what is shown in the picture).
What I am doing to try to avoid this problem, when I create the gesture:
panGesture = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(dragComponent:)];
panGesture.delegate = self;
panGesture.maximumNumberOfTouches = 1;
panGesture.minimumNumberOfTouches = 1;
panGesture.cancelsTouchesInView = NO;
[self.canvas.comp1 addGestureRecognizer: panGesture];
The cancelsTouchesInView seems to help get the functionality to the level it is at now. Another thing to try to cancel any gesture recognition when the touch starts in the toggle switch is in the delegate:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{ // basically is just return (view == switch1); for the switch
return ([self.canvas.comp1 handlesTouchesForView: [touch view]]) != YES;
}
This seems to allow the quick swipe mentioned earlier, but it doesn't work with all of them. I have a suspicion that a touch could be partially off the switch and still be partially activating for it.
The code is located at http://github.com/iaefai/Logic and any thoughts are appreciated.