탐색 모음 표시 / 숨기기
2 개의 막대 버튼으로 구성된 탐색 막대가있는 앱이 있습니다. 사용자가 화면을 두 번 탭하면이 탐색 표시 줄을 숨기고 표시하고 싶습니다.
처음에는 탐색 모음이 숨겨져 있어야합니다. 사용자가 화면을 두 번 탭하면 탐색 막대에 iPhone의 사진 갤러리에서 볼 수있는 것과 같은 애니메이션이 나타납니다.
어떻게해야합니까? 제안은 항상 감사합니다.
이것은 몇 줄의 코드에 맞지 않는 것이 아니지만 이것은 당신에게 도움이되는 한 가지 접근법입니다.
탐색 모음을 숨기려면
[[self navigationController] setNavigationBarHidden:YES animated:YES];
그것을 보여주기 위해 :
[[self navigationController] setNavigationBarHidden:NO animated:YES];
이 방법에 대한 설명서는 여기에서 볼 수 있습니다 .
"더블 클릭"또는 더블 탭, 서브 클래스를 수신 UIView
하고 해당 서브 클래스의 인스턴스를 뷰 컨트롤러의 view
속성으로 만듭니다.
뷰 서브 클래스에서 -touchesEnded:withEvent:
메소드를 재정의하고을 사용하여 연속 된 두 번의 탭 사이의 시간을 측정하여 지속 시간 동안 터치 수를 계산합니다 CACurrentMediaTime()
. 또는의 결과를 테스트하십시오 [touch tapCount]
.
두 개의 탭이 있으면 서브 클래스 된 뷰에서 NSNotification
뷰 컨트롤러가 수신 대기하도록 등록 된 문제가 발생합니다.
뷰 컨트롤러가 알림을 들으면 내비게이션 바의 현재 표시 상태에 따라 내비게이션 바의 isHidden
속성 을 읽어 액세스하여 위에서 언급 한 코드를 사용하여 내비게이션 바를 숨기거나 표시하는 선택기를 실행 합니다.
편집하다
탭 이벤트 처리에 대한 답변 중 일부는 iOS 3.1 이전에 유용했을 것입니다. 이 UIGestureRecognizer
클래스는 요즘 더블 탭을 처리하는 더 나은 방법 일 것입니다.
편집 2
탐색 모음을 숨기는 신속한 방법은 다음과 같습니다.
self.navigationController?.setNavigationBarHidden(true, animated: true)
그것을 보여주기 위해 :
self.navigationController?.setNavigationBarHidden(false, animated: true)
이 코드는 당신을 도울 것입니다.
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(showHideNavbar:)];
[self.view addGestureRecognizer:tapGesture];
-(void) showHideNavbar:(id) sender
{
// write code to show/hide nav bar here
// check if the Navigation Bar is shown
if (self.navigationController.navigationBar.hidden == NO)
{
// hide the Navigation Bar
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
// if Navigation Bar is already hidden
else if (self.navigationController.navigationBar.hidden == YES)
{
// Show the Navigation Bar
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
먼저 iOS 용 View Controller Programming Guide의 '탐색보기에 전체 화면 레이아웃 채택'섹션과 사용자 정의보기에 대한 섹션을 읽으십시오. Photos.app와 같은 것을하려고하면 스크롤보기를 사용하고있을 것입니다. 탐색 막대는 탐색 막대의 높이 (및 상태 표시 줄)를 설명하기 위해 스크롤 컨텐츠 삽입을 스크롤보기에 자동으로 추가하므로 바로 스크롤보기의 contentInset 속성을 다시 0 (UIEdgeInsetsZero)으로 재설정해야합니다. 네비게이션 바의 초기 상태를 설정하고 뷰가 나타나기 전에.
Then if you have a single tap that toggles the navigationBar and/or status bar to show or hide, you need to do two things in you toggling method. The first seems to be to save the scroll view's contentOffset property before changing the NavigationBar hidden property and restore your saved value to contentOffset right afterward. And second to again zero out the contentInset property to UIEdgeInsetsZero after changing the navigationBarHidden property. Also, if you are toggling the status bar, you need to change its state before you change the navigationBar's state.
In Swift try this,
self.navigationController?.navigationBarHidden = true //Hide
self.navigationController?.navigationBarHidden = false //Show
or
self.navigationController?.setNavigationBarHidden(true, animated: true) //Hide
self.navigationController?.setNavigationBarHidden(false, animated: true) //SHow
To hide Navigation bar :
[self.navigationController setNavigationBarHidden:YES animated:YES];
To show Navigation bar :
[self.navigationController setNavigationBarHidden:NO animated:YES];
Here is a very quick and simple solution:
self.navigationController.hidesBarsOnTap = YES;
This will work on single tap instead of double tap. Also it will change the behavior for the navigation controller even after pushing or popping the current view controller.
You can always modify this behavior in your controller within the viewWillAppear: and viewWillDisappear: actions if you would like to set the behavior only for a single view controller.
Here is the documentation:
One way could be by unchecking Bar Visibility "Shows Navigation Bar" In Attribute Inspector.Hope this help someone.
In Swift 4.2 and Xcode 10
self.navigationController?.isNavigationBarHidden = true //Hide
self.navigationController?.isNavigationBarHidden = false //Show
If you don't want to display Navigation bar only in 1st VC, but you want display in 2nd VC onword's
In your 1st VC write this code.
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = true //Hide
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = false //Show
}
hidesBarsOnTap
on UINavigationController property come out to handle just this with iOS8 SDK
SWIFT CODE: This works fully for iOS 3.2 and later.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let tapGesture = UITapGestureRecognizer(target: self, action: "hideNavBarOntap")let tapGesture = UITapGestureRecognizer(target: self, action: "hideNavBarOntap")
tapGesture.delegate = self
self.view.addGestureRecognizer(tapGesture)
then write
func hideNavBarOntap() {
if(self.navigationController?.navigationBar.hidden == false) {
self.navigationController?.setNavigationBarHidden(true, animated: true) // hide nav bar is not hidden
} else if(self.navigationController?.navigationBar.hidden == true) {
self.navigationController?.setNavigationBarHidden(false, animated: true) // show nav bar
}
}
참고URL : https://stackoverflow.com/questions/2926914/navigation-bar-show-hide
'IT' 카테고리의 다른 글
기존 Rails 열에서 부울에 : default => true 추가 (0) | 2020.06.08 |
---|---|
wget을 사용하여 웹 사이트에서 HTML이 아닌 모든 파일을 다운로드하는 방법은 무엇입니까? (0) | 2020.06.08 |
렌더링 문제 렌더링 중 예외 발생 : com.android.ide.common.rendering.api.LayoutlibCallback (0) | 2020.06.08 |
때때로 WCF 서비스 참조를 추가하면 빈 참조가 생성됩니다. (0) | 2020.06.08 |
Eclipse에서 빨간색 느낌표 아이콘은 무엇을 의미합니까? (0) | 2020.06.07 |