对于此线程上接受的解决方案: How do you shrink a UIPickerView on the iPhone?
我可以成功调整拾取器的大小。但是我的控制器中有两个选择器。当我为两个选择器执行练习时,它们会被重新调整大小,但是当将变换后的UIView添加到主视图时,其中一个变换后的子视图会丢失触摸输入。它总是被添加的子视图丢失触摸输入。我该如何解决这个问题?
以下是代码:
CGSize providerPickerSize = [providerPickerOutlet sizeThatFits:CGSizeZero];
CGSize amountPickerSize = [amountPickerOutlet sizeThatFits:CGSizeZero];
UIView *providerPickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, providerPickerSize.width, providerPickerSize.height)];
UIView *amountPickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, amountPickerSize.width, amountPickerSize.height)];
providerPickerTransformView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
amountPickerTransformView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
[providerPickerTransformView addSubview:providerPickerOutlet];
[amountPickerTransformView addSubview:amountPickerOutlet];
[self.view addSubview:amountPickerTransformView];
[self.view addSubview:providerPickerTransformView];
这里amountPickerTransformView失去了触摸输入。
使用XCode 4.3,iOS 5和故事板。
答案 0 :(得分:0)
首次添加视图失败的原因是,
您有两个相同第一帧的视图providerPickerTransformView
,另一个是amountPickerTransformView
。
现在amountPickerTransformView位于视图providerPickerTransformView
下方。所以选择器加amountPickerTransformView
没有接触。
您需要调整每个视图的框架,其中包含选择器appropriatley。
答案 1 :(得分:0)
只需更改第二个视图的x和y,即您想要的视图位于第一个视图的左侧。如下
UIView *providerPickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, providerPickerSize.width, providerPickerSize.height)];
UIView *amountPickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(providerPickerSize.width, 0.0f, amountPickerSize.width, amountPickerSize.height)];
快乐编码:)
编辑1
我可以在您的代码中找到的问题是
CGSize providerPickerSize = [providerPickerOutlet sizeThatFits:CGSizeZero];
CGSize amountPickerSize = [amountPickerOutlet sizeThatFits:CGSizeZero];
用
替换这两行中的CGSizeZero
CGSizeMake(CGFloat width, CGFloat height)
这肯定会解决您的问题。
快乐编码:)