在我的一个控制器中我使用自定义工具栏,我想在ios中获得默认工具栏(导航栏)的高度.我用过宏#define NAVBAR_HEIGHT self.navigationController.navigationBar.frame.size.height.
但是,当控制器没有嵌入导航堆栈时,宏返回零.
我不想使用44的常量,因为它可能在其他Apple设备上有所不同.
对于标签栏,我使用:
+(CGFloat)getTabBarHeight{
UITabBarController *tabBarController = [UITabBarController new];
CGFloat tabBarHeight = tabBarController.tabBar.frame.size.height;
return tabBarHeight;
}
Run Code Online (Sandbox Code Playgroud)
有没有这样的片段,所以我可以返回导航控制器工具栏的值?
自动呈现UISearchController和自己呈现搜索控制器之间的行为有所不同。
@implementation MyViewComtroller
// click search barbutton on right of navigationBar
- (void)searchAction:(id)sender {
ArticleSearchViewController *searchResultsController = [[ArticleSearchViewController alloc] init];
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
searchController.searchResultsUpdater = searchResultsController;
searchController.searchBar.delegate = searchResultsController;
searchController.delegate = searchResultsController;
searchController.hidesNavigationBarDuringPresentation = NO;
[self presentViewController:searchController animated:YES completion:nil];
}
@end
@implementation ArticleSearchViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ArticleDetailController * articleDetailController = [ArticleDetailController new];
[(UINavigationController *)self.presentingViewController pushViewController:articleDetailController animated:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
推送操作发生在UISearchController下面。
uinavigationbar uinavigationcontroller uisearchbar ios uisearchcontroller
我有一个主导航控制器,在其中设置背景颜色
override func viewDidLoad() {
super.viewDidLoad()
self.navigationBar.backgroundColor = UIColor.blue
self.navigationBar.isTranslucent = false
}
Run Code Online (Sandbox Code Playgroud)
但是,在那种情况下,我的导航栏会变成完全白色。当我将isTranslucent设置为true时,我的导航栏将变为透明,但这实际上不是我所需要的。我只想有蓝色的导航栏。
以防万一在我的导航控制器中
override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent }
Run Code Online (Sandbox Code Playgroud)
并在AppDelegate中设置色调颜色
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
Run Code Online (Sandbox Code Playgroud)
评论tintColor也没有帮助我。
我正在使用iOS 9目标将应用程序从iOS 10更新到iOS 11,当涉及导航栏时,这会发生在每个segue动画上.
动画以小于它应该处于的高度的小偏移开始,然后在视图完成动画时移动到适当的高度.
我没有对导航控制器做任何特别的事情,它发生在应用程序中的每一个.如果我以编程方式隐藏导航栏,则转换正常进行动画处理.
我正在以编程方式为我的应用程序设计一个注册页面视图,用户可以在其中输入自己的图像和一些信息。
在我的LoginController中,创建一个UINavigationController并带有我的RegisterController的rootviewcontroller,然后将其显示。
func handleRegisterButtonClicked() {
let registerController = RegisterController()
let navController = UINavigationController(rootViewController: registerController)
present(navController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
现在,我为他们添加了图片,以供单击以上传他们的照片。我希望此图片始终在导航栏下方显示30px,但要重叠在导航栏下方,从屏幕顶部显示30px:
class RegisterController: UIViewController {
...
func setupViews() {
profilePic.topAnchor.constraint(equalTo: view.topAnchor, constant: 30).isActive = true
}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以向profilePic添加约束,以便将其锚定在导航栏的底部(纵向和横向)?
每当在顶部视图控制器上按下后退按钮时,我都想返回到特定的视图控制器,而不是先前的视图控制器。我希望有一种方法可以某种方式覆盖后退按钮的功能。
编辑:
我得到这个工作:
self.navigationController?.popToRootViewController(animated: true)
唯一的问题是,在对其进行动画处理时,它会将中间视图控制器显示为根目录。
正在以编程方式快速使用导航栏,但无法在导航栏中显示栏按钮项,这是我所做的代码
override func viewDidLoad() {
super.viewDidLoad()
let navBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: 420, height: 65))
self.view.addSubview(navBar)
navBar.backgroundColor = hexStringToUIColor("4DC8BD")
let navigationItem = UINavigationItem()
self.title = "Transport APP"
let btn1 = UIButton(type: .custom)
btn1.setImage(UIImage(named: "Menu1"), for: .normal)
btn1.frame = CGRect(x: 30, y: 30, width: 30, height: 30)
btn1.addTarget(self, action: #selector(HomeViewController.menubuttonclick(_:)), for: .touchUpInside)
let item1 = UIBarButtonItem(customView: btn1)
self.navigationItem.setRightBarButtonItems([item1], animated: true)
}
@IBAction func menubuttonclick(_ sender:UIBarButtonItem )
{
print("this menu button click")
}
Run Code Online (Sandbox Code Playgroud)
我可以尝试多种方法,但无法获得如何在导航栏中显示显示栏按钮项的结果,
我以模态方式呈现了一个带有ViewController的NavigationController.
在ViewController中我可以看到这self.navigationController.isBeingPresented是真的.
但是,如果我现在在模态呈现的NavigationController上推送一个新的ViewController并弹回到原始的ViewController,则同一个check的调用isBeingPresented返回false.
文档很少但我不能真正解释这种不一致,除了它可能是一个错误?
删除地点后,我尝试将用户重定向到正确的页面。
navigationController?.popToRootViewController(animated: true)
Run Code Online (Sandbox Code Playgroud)
如果我想重定向到根目录,这将起作用。
navigationController?.popViewController(animated: true)
Run Code Online (Sandbox Code Playgroud)
如果我想重定向到上一个,这将起作用
但就我而言,我想重定向到特定页面而不是根目录或上一个页面。
在iOS中如何去做这样的事情?