2011-09-17 63 views
0

如何檢測用戶何時點擊UIPickerView中的選擇指示符?當用戶在UIPickerView中點擊選擇指示符時檢測?

如果沒有此選項,用戶必須滾動到其他行,然後再次返回,以便在拾取器向上滑動時選擇顯示在選擇指示器下的值。

非常感謝,
斯坦

enter image description here

更新:目前得到它通過我自己的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

密切相關:http://stackoverflow.com/questions/7455310/detect-when-user-taps-the-selection-indicator-in-a-uidatepicker – albertamg

+0

對不起,我沒有完全得到你的問題 –

+0

@albertamg:是的,他們密切相關。問題是我在'UIDatePicker'情況下找到的解決方案在'UIPickerView'情況下根本不起作用。 – Stine

回答

0

如果你想要顯示一些默認值,調用 - [picker selectRow:row inComponent:component animated:NO]初始化你的選擇器。
害怕,您無法知道用戶是否觸摸了已經選取的值並且不會更改它。

+0

謝謝,但不完全是我之後:/ – Stine

+0

Stive,如果你會認爲多一點你認爲它是唯一可能的功能。 –

+0

您無法使用UIPickerView,當用戶觸摸選取器中已突出顯示的值時,無法進行此操作。 –

相關問題