所以我试图在我的视图中定位一个自定义 UIPicker。我遵循 UICatalog 代码并在我的代码中应用相同的原则。
他们的定位似乎是:
CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero];
customPickerView.frame = [self pickerFrameWithSize:pickerSize];
这是如何运作的?他们似乎在代码中其他地方创建的常规选择器上调用“sizeThatFits”(我不需要),然后使用它来设置框架。
我如何在不需要两个选择器的情况下实现这样的事情?我希望我的自定义选择器位于视图的底部。
谢谢!
So I'm trying to position a custom UIPicker in my view. I am following the UICatalog code and applying the same principles in my code.
The way they seem to position it is:
CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero];
customPickerView.frame = [self pickerFrameWithSize:pickerSize];
How does that work? They seem to be calling "sizeThatFits" on a regular picker they have created elsewhere in the code (and which I don't need), and then use that to set up the frame.
How do I implement something like this without needing two pickers? I want my custom picker to be on the bottom of the view.
Thanks!
发布评论
评论(2)
这对我有用:
我通过在 nib 文件中拖动常规视图并使用相同的坐标来找到正确的大小和位置。
This worked for me:
I found out the correct size and position by dragging a regular view in a nib file and using the same coordinates.
如
文档
,某些类型的对象类返回固定大小。UIPickerView
就是其中之一,最好保持不变。因此,我们在UIPickerView
对象上使用该方法获得适当的大小。为此,您不需要第二个实例。您可以初始化一个没有框架的选取器对象,并在其上调用它以获得适当的大小。As mentioned in the
documentation
, certain types of class of objects return fixed sizes.UIPickerView
is one of them and is better left unchanged. So we get the appropriate size using that method on aUIPickerView
object. You don't need a second instance for this. You can initialize a picker object without a frame and call this on it to get the appropriate size.