在本文中,我们将详细介绍Swift-当TableView加载其内容时,在NavBar和TabBar之间有一个“加载”ViewController的各个方面,同时,我们也将为您带来关于、Appdeleg
在本文中,我们将详细介绍Swift - 当 TableView 加载其内容时,在 NavBar 和 TabBar 之间有一个“加载”ViewController的各个方面,同时,我们也将为您带来关于的有用知识。
本文目录一览:- Swift - 当 TableView 加载其内容时,在 NavBar 和 TabBar 之间有一个“加载”ViewController
- ">
- Appdelegate 跳转其他页面 获取当前屏幕显示的 viewcontroller 获取当前屏幕中 present 出来的 viewcontroller 获取当前导航控制器
- html – Twitter bootstrap 3 navbar navbar-right navbar-collapse之外
- iOS TableView reloadData 刷新列表 cell 乱跳、tableview 闪动的问题。
Swift - 当 TableView 加载其内容时,在 NavBar 和 TabBar 之间有一个“加载”ViewController
如何解决Swift - 当 TableView 加载其内容时,在 NavBar 和 TabBar 之间有一个“加载”ViewController
我有一个 TabBarController 作为我的 rootViewController。第一个选项卡是一个带有 NavigationBar 的 tableView。当 tableView 执行它的 fetch 请求并加载它的内容时,我展示了一个带有加载指示器的加载 viewController。 loadingVC 没有覆盖 tabBar,这很好,但它覆盖了 NavBar,我想避免这种情况。我基本上希望将 loadingVC 放置在 NavBar 和 TabBar 之间,因此它的视图框架被绑定 - 它的顶部到 NavBar 的底部,它的底部到 TabBar 的顶部。我无法使用此功能,我以为我可以在 .modalPresentationStyle 中找到解决方案,但那里的选项并未涵盖我所描述的内容。
场景委托代码:
window = UIWindow(frame: UIScreen.main.bounds)
window?.windowScene = windowScene
let rootVC = TBController()
window?.rootViewController = rootVC
window?.makeKeyAndVisible()
TabBarController:
class TBController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
tabBar.isTranslucent = false
// Article TVC
let articleVC = UINavigationController(rootViewController: ArticlesTVC())
let articleIcon = UITabBarItem(title: "News",image: UIImage(systemName: "newspaper"),tag: 0)
articleVC.tabBarItem = articleIcon
articleVC.navigationBar.prefersLargeTitles = false
articleVC.navigationBar.isTranslucent = false
articleVC.navigationBar.barTintColor = .systemBackground
articleVC.definesPresentationContext = true
articleVC.view.clipsToBounds = true
}
加载 VC:
class LoadingVC: UIViewController {
var loadingLabel: UILabel = {
let loadingLabel = UILabel()
loadingLabel.text = "Loading articles..."
loadingLabel.textAlignment = .center
loadingLabel.translatesAutoresizingMaskIntoConstraints = false
loadingLabel.font = .systemFont(ofSize: 18,weight: .heavy)
loadingLabel.backgroundColor = .systemBackground
return loadingLabel
}()
var loadingActivityIndicator: UIActivityIndicatorView = {
let indicator = UIActivityIndicatorView()
indicator.style = .large
indicator.color = .white
indicator.startAnimating()
indicator.translatesAutoresizingMaskIntoConstraints = false
indicator.backgroundColor = .systemBackground
return indicator
}()
var blurEffectView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .regular)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.clipsToBounds = true
blurEffectView.alpha = 0.8
blurEffectView.translatesAutoresizingMaskIntoConstraints = false
blurEffectView.backgroundColor = .systemBackground
return blurEffectView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
view.addSubview(loadingLabel)
view.addSubview(blurEffectView)
blurEffectView.frame = view.bounds
view.addSubview(loadingActivityIndicator)
loadingActivityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
loadingActivityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
view.addSubview(loadingLabel)
loadingLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
loadingLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor,constant: 50).isActive = true
}
}
表视图:
class ArticlesTVC: UITableViewController {
let loadingVC = LoadingVC()
override func viewDidLoad() {
super.viewDidLoad()
loadingVC.modalPresentationStyle = .currentContext
loadingVC.modalTransitionStyle = .crossdissolve
dispatchQueue.main.async {
self.present(self.loadingVC,animated: true)
}
tableView.separatorStyle = .none
tableView.backgroundColor = .systemBackground
}
}
解决方法
您最好将其作为 tableView 上方的视图,并在您的内容加载后为其 isHidden 属性分配 true。故事板有点乱,虽然有办法解决这个问题,但在你的情况下,你正在以编程方式添加到视图控制器的视图中,所以将代码添加到自定义视图中,然后在表视图上添加该视图应该没问题。然后,您可以随意调用自定义视图的方法。
" alt="
">
<div><div>
<button type="button"data-toggle="collapse"
data-target="#example-navbar-collapse">
<span>切换导航</span>
<span></span>
<span></span>
<span></span>
</button>
<ahref="#">菜鸟教程</a>
</div>
<divid="example-navbar-collapse">
<ul>
<li><a href="#">iOS</a></li>
<li><a href="#">SVN</a></li>
<li>
<a href="#"data-toggle="dropdown">
Java <b></b>
</a>
<ul>
<li><a href="#">jmeter</a></li>
<li><a href="#">EJB</a></li>
<li><a href="#">Jasper Report</a></li>
<li></li>
<li><a href="#">分离的链接</a></li>
<li></li>
<li><a href="#">另一个分离的链接</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Appdelegate 跳转其他页面 获取当前屏幕显示的 viewcontroller 获取当前屏幕中 present 出来的 viewcontroller 获取当前导航控制器
Appdelegate 跳转其他页面
UITabBarController *tab = (UITabBarController *)_window.rootViewController;
UINavigationController *nav = tab.viewControllers[tab.selectedIndex];
MessageViewController *vc = [[MessageViewController alloc] init]; 需要跳转的页面
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
// 获取当前屏幕显示的 viewcontroller
- (UIViewController *)getCurrentVC{
UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
if (!window) {
return nil;
}
UIView *tempView;
for (UIView *subview in window.subviews) {
if ([[subview.classForCoder description] isEqualToString:@"UILayoutContainerView"]) {
tempView = subview;
break;
}
}
if (!tempView) {
tempView = [window.subviews lastObject];
}
id nextResponder = [tempView nextResponder];
while (![nextResponder isKindOfClass:[UIViewController class]] || [nextResponder isKindOfClass:[UINavigationController class]] || [nextResponder isKindOfClass:[UITabBarController class]]) {
tempView = [tempView.subviews firstObject];
if (!tempView) {
return nil;
}
nextResponder = [tempView nextResponder];
}
return (UIViewController *)nextResponder;
}
// 获取当前屏幕中 present 出来的 viewcontroller。
- (UIViewController *)getPresentedViewController
{
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
if (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return topVC;
}
// 获取当前导航控制器
- (BaseNavigationController *)getNavController{
BaseTableBarControllerView *tabVC = (BaseTableBarControllerView *)self.window.rootViewController;
tabVC.selectedIndex = 2;
BaseNavigationController *pushClassStance = (BaseNavigationController *)tabVC.selectedViewController;
return pushClassStance;
}
html – Twitter bootstrap 3 navbar navbar-right navbar-collapse之外
http://jsfiddle.net/aQwUZ/3/
<div> <div> <div> <a data-target=".nav-collapse" data-toggle="collapse"> <span></span> <span></span> <span></span> </a> <a href="#">BRAND</a> <ul> <li> <a href="#">Fixed Link</a> </li> </ul> <div> <ul> <li><a href="#">L1</a></li> <li><a href=#">L2</a></li> </ul> </div> </div> </div> </div>
一个Twitter引导程序导航栏,在移动响应视图中,“固定链接”在标题中保持可见.
现在,在bootstrap 3中,升级我的代码后,我只能:
http://jsfiddle.net/EC3Ly/4/
<navrole="navigation"> <div> <div> <button type="button"data-toggle="collapse" data-target=".navbar-collapse"> <span></span> <span></span> <span></span> </button> <ahref="#">BRAND</a> </div> <ul> <li> <a href="#">Fixed Link</a> </li> </ul> <div> <ul> <li><a href="#">L1</a></li> <li><a href=#">L2</a></li> </ul> </div> </div> </nav>
在移动响应视图中,我得到2行……
我试图在“navbar-header”节点http://jsfiddle.net/EC3Ly/5/或第一个“navbar-header”中包装但没有成功.
我错过了什么?
谢谢,
亚历山大
解决方法
.navbar-header { .clearfix(); @media (min-width: @grid-float-breakpoint) { float: left; } }
您可以使用媒体查询和css来撤消此clearfix(并在折叠下拉列表之前添加新内容)
.navbar-right {float: right !important;} @media(max-width:767px) { .navbar-right {margin-right:20px;} .navbar-header:after { clear: none; } .navbar-nav.navbar-right > li { float: left; } .navbar-collapse:before {clear:both;} .navbar-collapse {overflow-y: hidden;} .navbar-collapse.in {overflow-y: visible;} .navbar{border-color: #101010; border-width: 0 0 1px;} .navbar-collapse.in > ul {border-color: #101010; border-top:1px double;} } }
演示:http://bootply.com/82366
媒体查询还在较小的屏幕上为导航栏右侧添加了一个浮动.要在生产中使用此代码,您可能会修复边框以及可能的navbar css转换.
iOS TableView reloadData 刷新列表 cell 乱跳、tableview 闪动的问题。
解决方法:
在 iOS 11Self-Sizing 自动打开后,contentSize 和 contentOffset 都可能发生改变。可以通过以下方式禁用
self.estimatedRowHeight = 0;
self.estimatedSectionHeaderHeight = 0;
self.estimatedSectionFooterHeight = 0;
在 iOS 10 以下 通过以下协议方法设置精准高度就可以了
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(7_0);
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);
今天的关于Swift - 当 TableView 加载其内容时,在 NavBar 和 TabBar 之间有一个“加载”ViewController的分享已经结束,谢谢您的关注,如果想了解更多关于的相关知识,请在本站进行查询。
本文标签: