I use code as below to show a PickerView, but is not located at middle of center, then if I rotated, the PickerView is not to rotated, what should I have to implement for tight showing?
Code:
- (void)showPickerView {
if (pickerView == nil) {
pickerView = [[UIDatePicker alloc] initWithFrame: CGRectMake(0.0, 0.0, 0.0, 0.0)];
}
if (self.pickerView.superview == nil) {
[self.view.window addSubview: self.pickerView];
// size up the picker view to our screen and compute the start/end frame origin
// for our slide up animation compute the start frame
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGSize pickerSize = [self.pickerView sizeThatFits:CGSizeZero];
CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height);
self.pickerView.frame = startRect;
// compute the end frame
CGRect pickerRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height - pickerSize.height, pickerSize.width, pickerSize.height);
// start the slide up animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
// we need to perform some post operations after the animation is complete
[UIView setAnimationDelegate:self];
self.pickerView.frame = pickerRect;
// shrink the table vertical size to make room for the date picker
CGRect newFrame = detail.frame;
newFrame.size.height -= self.pickerView.frame.size.height;
self.detail.frame = newFrame;
[UIView commitAnimations];
}
}