如何检测用户何时点击UIPickerView中的选择指示器?
如果没有这个,用户必须滚动到其他一行然后再返回以选择当选择器向上滑动时选择指示器下显示的值。
非常感谢,
斯坦
更新:目前通过使用我自己的SensitivePickerView
(在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
......和实施:
#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
根本不理想,但它有效:/
答案 0 :(得分:0)
如果您想要显示某个默认值,请调用 - [picker selectRow:row inComponent:component animated:NO]初始化您的选择器。
害怕,你无法知道用户是否触摸了已经选择的值并且没有改变它。