Adicionando uma View Uipickervie
-
23-09-2019 - |
Pergunta
Estou tentando ter um slide uipickerview da parte inferior da tela (por cima de uma barra de guia), mas não consigo fazer com que apareça. O código real da animação é proveniente de um dos projetos de código de exemplo da Apple (DATECELL). Estou chamando esse código do primeiro controlador de exibição (FirstViewController.m) no controlador da barra de guias.
- (IBAction)showModePicker:(id)sender {
if (self.modePicker.superview == nil) {
[self.view.window addSubview:self.modePicker];
// 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.modePicker sizeThatFits:CGSizeZero];
CGRect startRect = CGRectMake(0.0, screenRect.origin.y + screenRect.size.height, pickerSize.width, pickerSize.height);
self.modePicker.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.modePicker.frame = pickerRect;
// shrink the vertical size to make room for the picker
CGRect newFrame = self.view.frame;
newFrame.size.height -= self.modePicker.frame.size.height;
self.view.frame = newFrame;
[UIView commitAnimations];
// add the "Done" button to the nav bar
self.navigationItem.rightBarButtonItem = self.doneButton;
}}
Sempre que essa ação dispara através de um uibarbuttonitem que vive em um Uinavigationbar (que está tudo sob o FirstViewController), nada acontece. Alguém pode oferecer alguns conselhos?
Solução
Acontece que eu tinha perdido o fato muito importante de que o Uipickerview também havia sido definido no Builder de Interface ... depois de fazer isso e conectar a saída, tudo está funcionando!