开发者

move a uipickerview

开发者 https://www.devze.com 2023-02-05 21:01 出处:网络
I have this problem: if I use a uidatepicker, everything goes fine: I have this code: datePickerView.frame = CGRectMake(0, 264, 320, 216);

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!


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消