특정 뷰 컨트롤러에서 탐색 모음을 숨기는 방법
두 개의 스플래시 화면 iPhone 앱을 만들었습니다. 그 후 사용자는 첫 번째보기로 이동합니다. UINavigationController를 추가했습니다. 완벽하게 잘 작동합니다.
오프닝 뷰에 대한 탐색 모음 만 제거하려면 어떻게합니까?
MainWindow
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.splashScreen = [[SplashScreen alloc]
initWithNibName:@"SplashScreen"
bundle:nil];
if (self.pageController == nil) {
openingpage *page=[[openingpage alloc]initWithNibName:@"openingpage" bundle:[NSBundle mainBundle]];
self.pageController = page;
[page release];
}
[self.navigationController pushViewController:self.pageController animated:YES];
[window addSubview:splashScreen.view];
[splashScreen displayScreen];
[self.window makeKeyAndVisible];
return YES;
}
뷰 컨트롤러 내에서 다음 방법을 시도하십시오.
// swift
self.navigationController?.setNavigationBarHidden(true, animated: true)
// objective-c
[self.navigationController setNavigationBarHidden:YES animated:YES];
추가 설명 :
UINavigationController
전체 탐색 컨트롤러의 탐색 모음을 숨기거나 표시 할 수있는 navigationBarHidden 속성이 있습니다.
다음 계층 구조를 살펴 보겠습니다.
--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3
세 UIViewController는 각각 UINavigationController에 있기 때문에 동일한 탐색 모음을 갖습니다. 예를 들어, UIViewController2에 대한 막대를 숨기고 싶을 때 (실제로 어느 것이 든 상관 없음), UIViewController2에 다음과 같이 작성하십시오.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES]; //it hides the bar
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES]; // it shows the bar back
}
스위프트 4 :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
navigationController?.setNavigationBarHidden(false, animated: false)
}
이것은 나를 위해 일했습니다.
스위프트 4
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
//reappears navigation bar on next page
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
이전에 숨겨 졌는지 기억하는 것이 좋습니다.
private var navigationBarWasHidden = false
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Save if it was hidden initially
self.navigationBarWasHidden = self.navigationController?.isNavigationBarHidden ?? false
// Hide the Navigation Bar
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Show the Navigation Bar
self.navigationController?.setNavigationBarHidden(self.navigationBarWasHidden, animated: animated)
}
Use below one line code to hide Navigation bar in Swift3 and Swift4
navigationController?.setNavigationBarHidden(true, animated: true)
To show Navigation bar
navigationController?.setNavigationBarHidden(false, animated: true)
In c# or Xamarin.IOS, this.NavigationController.NavigationBar.Hidden = true;
Present the opening view modally, or;
- don't add it to your navigation controller
- present it before the navigation controller.
- Once everything has loaded, dismiss the opening view and show the navigation controller (both without animation).
Taking an example from this thread: How can I display a splash screen for longer on an iPhone?
-(void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:splashView];
[NSThread detachNewThreadSelector:@selector(getInitialData:)
toTarget:self withObject:nil];
}
-(void)getInitialData:(id)obj {
[NSThread sleepForTimeInterval:3.0]; // simulate waiting for server response
[splashView removeFromSuperview];
[window addSubview:tabBarController.view];
}
'program story' 카테고리의 다른 글
네면 모두에 박스 섀도우를 적용하는 방법은 무엇입니까? (0) | 2020.11.10 |
---|---|
jQuery bind click * ANYTHING * but * ELEMENT * (0) | 2020.11.10 |
JavaScript로 날짜를 더하거나 빼는 방법은 무엇입니까? (0) | 2020.11.10 |
Laravel 뒤로 버튼 (0) | 2020.11.09 |
Android Studio 2.0에서 에뮬레이터를 시작할 수 없습니다. (0) | 2020.11.09 |