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?
精彩评论