移动 uipickerview
我有这个问题: 如果我使用 uidatepicker,一切都会顺利: 我有这个代码:
datePickerView.frame = CGRectMake(0, 264, 320, 216);
datePickerView.bounds = CGRectMake(0, -108, 320, 216);
并且 datepicker 是一半在底部(就像我想要的(仅用于测试))
但是如果我使用 uipickerview,并且我使用相同的代码:
genderPickerView.frame = CGRectMake(0, 264, 320, 216);
genderPickerView.bounds = CGRectMake(0, -108, 320, 216);
但是 pickerview 位于底部,而不是一半在底部就像日期选择器... 有什么问题吗? 提前致谢!
I have this problem:
if I use a uidatepicker, everything goes fine:
I have this code:
datePickerView.frame = CGRectMake(0, 264, 320, 216);
datePickerView.bounds = CGRectMake(0, -108, 320, 216);
and the datepicker is half on the bottom (like I want ( only for test))
but if I use a uipickerview, and I use the same code:
genderPickerView.frame = CGRectMake(0, 264, 320, 216);
genderPickerView.bounds = CGRectMake(0, -108, 320, 216);
but the pickerview is on the bottom, not half on the bottom like the datepicker...
what's the problem??
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您更改了视图的绘图边界。我想为什么选择器视图之间不同的答案是由于每个控件的实际实现 - 一个必须在边界原点绘制,而另一个必须在框架原点绘制。
通过将边界的 y 原点设置为 -108,视图的可绘制区域原点现在比实际视图位置高 108 像素。一般来说,您永远不想在边界上设置原点,特别是当您不拥有控件时。只需使用帧位置:0,156,320,216,它们的行为应该相同。
有关何时应使用框架、边界或中心视图属性的详细说明,请参阅 UIView的frame、bounds、center、origin,什么时候用什么?
Its because you have changed the drawing bounds of the view. I suppose the answer to why it is different between picker views is due to the actual implementation of each control - one must draw at the bounds origin, whilst the other the frame origin.
By setting the y origin of the bounds to -108 the drawable area origin of the view is now 108 pixels above the actual view position. in general you never want to set the origin on the bounds especially when you dont own the control. Just use frame position: 0,156, 320, 216 and they should both behave the same.
for a good explanation of when you should use frame, bounds or center view properties, see UIView's frame, bounds, center, origin, when to use what?