如何檢測用戶何時點擊UIPickerView中的選擇指示符?當用戶在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
不理想,但它的工作原理:/
密切相關:http://stackoverflow.com/questions/7455310/detect-when-user-taps-the-selection-indicator-in-a-uidatepicker – albertamg
對不起,我沒有完全得到你的問題 –
@albertamg:是的,他們密切相關。問題是我在'UIDatePicker'情況下找到的解決方案在'UIPickerView'情況下根本不起作用。 – Stine