У меня есть UIPickerView, который анимируется вверх и вниз в UITableViewController. Я адаптировал пример из Apple (DateCell). UIPickerView создается программно, без файлов пера.
В портретном режиме все выглядит красиво. Когда я поворачиваю симулятор (я не тестирую устройство), UITableView вращается хорошо, но сборщик остается там, где он был. Я прочитал тонны тем на эту тему, и многие разработчики, кажется, имеют проблемы со сборщиками, которые ведут себя странно в ландшафтном режиме, но, по крайней мере, их сборщики вращаются. Я создал подкласс UIPickerView, как описано в этой ссылке: http://www.llamagraphics.com/developer/using-uidatepicker-landscape-mode, но это не помогло решить проблему с вращением.
Я попытался повернуть средство выбора с помощью преобразования, но оно выглядело очень странно, как будто сломано.
Я подозреваю, что проблема в том, что я использую сборщик внутри UITableViewController, и поэтому я добавляю его как подвид self.view.window. Если я попытаюсь добавить средство выбора в качестве подвида self.view, появится только белая рамка (без средства выбора).
Какие-либо предложения?
Код инициализации в подклассе UITableViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.pickerView.superview == nil)
{
//Initialization code
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGRect initFrame = orientation == UIInterfaceOrientationPortrait ? CGRectMake(0, 0, 320, 200) : CGRectMake(0, 0, 480, 160);
self.pickerView = [[RotatingUIPickerView alloc] initWithFrame:initFrame];
[self.pickerView setDelegate:self];
[self.pickerView setShowsSelectionIndicator:YES];
[self.pickerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
[self.view.window addSubview:self.pickerView];
// 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 setFrame: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 setFrame:pickerRect];
[UIView commitAnimations];
}
}
Реализация подкласса UIPicker, как описано по ссылке выше:
- (id)initWithFrame:(CGRect)frame
{
if (self == [super initWithFrame:frame])
{
for (UIView * subview in self.subviews)
{
[subview setFrame:self.bounds];
}
}
return self;
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
if (self == [super initWithCoder: aDecoder])
{
for (UIView * subview in self.subviews)
{
[subview setFrame:self.bounds];
}
}
return self;
}