How can I detect when the user taps the selection indicator in a UIPickerView?
Without this the user has to scroll to some other row and then back again to pick the value which is displayed under the selection indicator when the picker slides up.
Thanks a lot,
Stine
UPDATE: Currently getting it to work by using my own SensitivePickerView
(got the idea here Responding to touchesBegan in UIPickerView instead of UIView):
#import <UIKit/UIKit.h>
@protocol SensitivePickerViewDelegate <UIPickerViewDelegate>
- (void) pickerViewWasTouched;
@end
@interface SensitivePickerView : UIPickerView
@property (nonatomic, assign) id<SensitivePickerViewDelegate> delegate;
@end
... and the implementation:
#import "SensitivePickerView.h"
@interface SensitivePickerView ()
- (UIView *) getNextResponderView:(NSSet *)touches withEvent:(UIEvent *)event;
@end
@implementation SensitivePickerView
@synthesize delegate;
- (void) setDelegate:(id<SensitivePickerViewDelegate>)aDelegate {
[super setDelegate:aDelegate];
delegate = aDelegate;
}
- (UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return self;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIView *hitTestView = [self getNextResponderView:touches withEvent:event];
[hitTestView touchesBegan:touches withEvent:event];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UIView *hitTestView = [self getNextResponderView:touches withEvent:event];
[hitTestView touchesMoved:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UIView *hitTestView = [self getNextResponderView:touches withEvent:event];
[hitTestView touchesEnded:touches withEvent:event];
[self.delegate pickerViewWasTouched];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
UIView *hitTestView = [self getNextResponderView:touches withEvent:event];
[hitTestView touchesCancelled:touches withEvent:event];
}
- (UIView *) getNextResponderView:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
UIView *hitTestView = [super hitTest:point withEvent:event];
return (hitTestView == self) ? nil : hitTestView;
}
@end
Not ideal at all but it works :/