0

当点击 a 时,我将 a 添加UIPickerView到我的视图UILabel中。当我自己添加时UIPickerView,它工作正常:

static const CGFloat HMCMeasurePickerHeight = 200.0;
CGRect measurePickerFrame = CGRectMake(0.0,
                                       CGRectGetHeight(self.view.window.bounds) - HMCMeasurePickerHeight,
                                       CGRectGetWidth(self.view.window.bounds),
                                       HMCMeasurePickerHeight);
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:measurePickerFrame];
picker.dataSource = self;
picker.delegate = self;
picker.showsSelectionIndicator = YES;
[self.view addSubview:picker];

但是,我想要一个带有它的工具栏,所以我将它包装在一个UIView

static const CGFloat HMCMeasurePickerAccessoryHeight = 44.0;
static const CGFloat HMCMeasurePickerHeight = 200.0;
CGRect measurePickerSuperviewFrame = CGRectMake(0.0,
                                                CGRectGetHeight(self.view.window.bounds) - HMCMeasurePickerHeight - HMCMeasurePickerAccessoryHeight,
                                                CGRectGetWidth(self.view.window.bounds),
                                                HMCMeasurePickerAccessoryHeight);
UIView *measurePicker = [[UIView alloc] initWithFrame:measurePickerSuperviewFrame];
CGRect measurePickerAccessoryFrame = CGRectMake(0.0,
                                                0.0,
                                                CGRectGetWidth(self.view.window.bounds),
                                                HMCMeasurePickerAccessoryHeight);
UIToolbar *measurePickerAccessory = [[UIToolbar alloc] initWithFrame:measurePickerAccessoryFrame];
measurePickerAccessory.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *rightAlignSpacer = [[UIBarButtonItem alloc]
                                     initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                     target:nil
                                     action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                            target:self
                                                                            action:@selector(dismissMeasurePicker:)];
measurePickerAccessory.items = @[rightAlignSpacer, doneButton];
[measurePicker addSubview:measurePickerAccessory];
CGRect measurePickerFrame = CGRectMake(0.0,
                                       HMCMeasurePickerAccessoryHeight,
                                       CGRectGetWidth(self.view.window.bounds),
                                       HMCMeasurePickerHeight);
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:measurePickerFrame];
picker.dataSource = self;
picker.delegate = self;
picker.showsSelectionIndicator = YES;
[measurePicker addSubview:picker];
[self.view addSubview:measurePicker];

现在,当我尝试滚动时,UIPickerView什么也没有发生。我可以成功点击我添加的完成按钮,只是UIPickerView没有响应。我尝试了设置picker.userInteractionEnabled = YES,但没有效果(鉴于第一个示例,它似乎默认为YES)。

4

1 回答 1

1

我想问题是 measurePicker 的帧大小小于picker。我建议你检查这一行。NSLog 最后一帧 measurePicker 看看它返回的宽度和高度。

于 2013-08-14T15:09:06.653 回答