ios - UIRefreshControl oculto/oscurecido por UINavigationBar de mi UINavigationController
uitableview cocoa-touch (6)
No llame a -setTranslucent: en su UINavigationBar . Luego, su control de actualización se colocará correctamente, debajo de la barra de navegación.
Estoy intentando utilizar un UIRefreshControl dentro de mi UITableViewController que está dentro de un UINavigationController , que tiene su propiedad hidesNavigationBar establecida en NO (para que la barra de navegación esté visible).
El UIRefreshControl funciona, pero está oscurecido por UINavigationBar . Me sorprende que no pueda encontrar a nadie más que haya tenido este problema.
Posibles puntos relevantes:
- Configuré el
rootViewControllerde miUIWindowpara que sea miUINavigationController. - Configuré el controlador de vista inicial del
UINavigationControllerestableciendo la propiedadviewControllersdelUINavigationController. - Mi subclase
UITableViewControllerseUITableViewControlleruna instancia con un plumín. -
UIRefreshControlmiUIRefreshControlen el métodoviewDidLoadde mi subclaseUITableViewController. Establecí la propiedadrefreshControlde la subclaseUITableViewControlleren este método. - El
UIRefreshControlfunciona perfectamente bien, y puedo ver una parte de él, pero está oscurecido por miUINavigationBar. Parece completamente normal si configurohidesNavigationBarenYES(pero no quiero ocultarlo).
Editar:
El código usado para crear y posicionar mi UIRefreshControl es:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self
action:@selector(toggleRefresh:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
Este fragmento de código se encuentra en el método viewDidLoad de mi subclase UITableViewController , que es un controlador de vista hijo de un UINavigationViewController .
Para aquellos que apuntan a iOS 7, parece haber un nuevo problema presente donde el UIRefreshControl se dibuja detrás de la UITableView de backgroundView UITableView . Experimenté esto tanto al inicializar UIRefreshControl programáticamente como a partir de un guión gráfico. Una solución simple es actualizar la zPosition de UIRefreshControl en viewDidLoad de su UITableViewController :
self.refreshControl.layer.zPosition = self.tableView.backgroundView.layer.zPosition + 1;
En iOS 7, self.view está debajo de la barra de navegación, excepto que escribes algo de la siguiente manera:
self.edgesForExtendedLayout = UIRectEdgeNone; // or UIRectEdgeAll & ~UIRectEdgeTop
o
self.navigationViewController.navigationbar.translucent = NO;
Encontré una solución real, aquí está:
Tengo un UIViewController dentro de un UINavigationController con una UINavigationController NavigationBar translúcida. Dentro del UIViewController está el UITableView .
Quiero agregar un UIRefreshControl pero cuando lo hago, está oculto por NavigationBar , como usted explica.
Aquí está mi código para que funcione:
// Add a UITableViewController
self.tblViewController = [[UITableViewController alloc] init];
// Set the UITableView to it
self.tblViewController.tableView = self.tblView;
// Initialize the UIRefreshControl and set it''s method
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];
// Set the RefreshControl to the UITableViewController
self.tblViewController.refreshControl = self.refreshControl;
// Here is the thing ! Just change the contentInset to push down the UITableView content to 64 pixels (StatusBar + NavigationBar)
self.tblView.contentInset = UIEdgeInsetsMake(64.f, 0.f, 0.f, 0.f);
Con este código, su UITableViewController mostrará RefreshControl perfección y mantendrá el efecto translúcido de la RefreshControl NavigationBar cuando se desplaza hacia abajo por las celdas.
Me parece un error, porque solo se produce cuando la propiedad contentOffset de tableView es 0
ver esta pregunta
UIRefreshControl no se muestra espinoso al llamar a beginRefreshing y contentOffset es 0
Lo arreglé con el siguiente código (método para UITableViewController):
- (void)beginRefreshingTableView {
[self.refreshControl beginRefreshing];
if (self.tableView.contentOffset.y == 0) {
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^(void){
self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
} completion:^(BOOL finished){
}];
}
}