[ios] presentViewController 및 탐색 모음 표시

뷰 컨트롤러 계층이 있고 최상위 컨트롤러가 모달로 표시되며 사용할 때 탐색 모음을 표시하는 방법을 알고 싶습니다.

'UIViewController:presentViewController:viewControllerToPresent:animated:completion'

‘presentViewController : animated : completion :’에 대한 문서 참고 :

‘iPhone 및 iPod touch에서 제시된보기는 항상 전체 화면입니다. iPad에서 프레젠테이션은 modalPresentationStyle 속성의 값에 따라 다릅니다. ‘

‘modalPresentationStyle’의 경우 문서는 다음과 같이 말합니다.

프리젠 테이션 스타일은 모달로 제공되는 뷰 컨트롤러가 화면에 표시되는 방식을 결정합니다. iPhone 및 iPod touch에서 모달보기 컨트롤러는 항상 전체 화면으로 표시되지만 iPad에는 몇 가지 다른 프레젠테이션 옵션이 있습니다.

보기 컨트롤이 표시되면 탐색 모음이 상태 표시 줄 아래에 표시되도록하는 방법이 있습니까? iPhone / iPod 옵션이없고 iPad에서만 문서를 해석해야합니까?

이전에는 'UIViewController:presentModalViewController:animated'잘 작동 하는 것을 사용 했지만 iOS 5.0부터 API가 더 이상 사용되지 않으므로 새 API로 전환하고 있습니다.

시각적으로 제가하고자하는 것은 예전 API처럼 화면 하단에서 새 컨트롤러를 밀어 넣는 것입니다.

[코드 업데이트] :

// My root level view:
UIViewController *vc = [[RootViewController alloc] 
                            initWithNibName:nil 
                            bundle:[NSBundle mainBundle]];
navController = [[UINavigationController alloc] initWithRootViewController:vc];        
....

// Within the RootViewController, Second view controller is created and added 
// to the hierarchy. It is this view controller that is responsible for 
// displaying the DetailView:
SecondTierViewController *t2controller = [[SecondTierViewController alloc] 
                                           initWithNibName:nil
                                           bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:t2controller animated:YES];

// Created by SecondTierViewController 
DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil                                                                                 
                                        bundle:[NSBundle mainBundle]];  

controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
controller.modalPresentationStyle = UIModalPresentationCurrentContext;

[self.navigationController presentViewController:controller 
                                        animated:YES 
                                        completion:nil];



답변

iPhone에 뷰 컨트롤러를 모달로 표시하면 내비게이션 컨트롤러의 상위 뷰 컨트롤러에 표시하거나 다른 방법으로 표시하더라도 항상 전체 화면으로 표시되는 것은 사실입니다. 그러나 다음 해결 방법으로 항상 탐색 모음을 표시 할 수 있습니다.

해당 뷰 컨트롤러를 표시하는 대신 루트 뷰 컨트롤러를 원하는 뷰 컨트롤러로 설정하여 탐색 컨트롤러를 모달로 표시합니다.

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = 
    [[UINavigationController alloc] initWithRootViewController:myViewController];

//now present this navigation controller modally 
[self presentViewController:navigationController
                   animated:YES
                   completion:^{

                        }];

보기가 모달로 표시되면 탐색 모음이 표시되어야합니다.


답변

Swift 5.*

항해:

guard let myVC = self.storyboard?.instantiateViewController(withIdentifier: "MyViewController") else { return }
let navController = UINavigationController(rootViewController: myVC)

self.navigationController?.present(navController, animated: true, completion: nil)

돌아 가지:

self.dismiss(animated: true, completion: nil)

스위프트 2.0

항해:

let myVC = self.storyboard?.instantiateViewControllerWithIdentifier("MyViewController");
let navController = UINavigationController(rootViewController: myVC!)

self.navigationController?.presentViewController(navController, animated: true, completion: nil)

돌아 가지:

self.dismissViewControllerAnimated(true, completion: nil)


답변

다음을 사용할 수 있습니까?

[self.navigationController pushViewController:controller animated:YES];

돌아 가기 (제 생각에) :

[self.navigationController popToRootViewControllerAnimated:YES];


답변

ios7에서 동일한 문제가 발생했습니다. 나는 그것을 선택기에서 불렀고 ios7과 ios8 모두에서 작동했습니다.

[self performSelector: @selector(showMainView) withObject: nil afterDelay: 0.0];

- (void) showMainView {
    HomeViewController * homeview = [
        [HomeViewController alloc] initWithNibName: @
        "HomeViewController"
        bundle: nil];
    UINavigationController * navcont = [
        [UINavigationController alloc] initWithRootViewController: homeview];
    navcont.navigationBar.tintColor = [UIColor whiteColor];
    navcont.navigationBar.barTintColor = App_Theme_Color;
    [navcont.navigationBar
    setTitleTextAttributes: @ {
        NSForegroundColorAttributeName: [UIColor whiteColor]
    }];
    navcont.modalPresentationStyle = UIModalPresentationFullScreen;
    navcont.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self.navigationController presentViewController: navcont animated: YES completion: ^ {

    }];
}


답변

모든 [self.navigationController pushViewController:controller animated:YES];작업은 전환을 애니메이션하고 탐색 컨트롤러 스택 및 기타 멋진 탐색 모음 애니메이션에 추가하는 것입니다. 막대 애니메이션에 신경 쓰지 않으면이 코드 작동합니다. 새 컨트롤러에 막대가 표시되고 대화 형 팝 제스처가 나타납니다!

//Make Controller
DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil                                                                                 
                                    bundle:[NSBundle mainBundle]];  
//Customize presentation
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
controller.modalPresentationStyle = UIModalPresentationCurrentContext;

//Present controller
[self presentViewController:controller 
                   animated:YES 
                 completion:nil];
//Add to navigation Controller
[self navigationController].viewControllers = [[self navigationController].viewControllers arrayByAddingObject:controller];
//You can't just [[self navigationController].viewControllers addObject:controller] because viewControllers are for some reason not a mutable array.

편집 : 죄송합니다. presentViewController가 전체 화면을 채울 것입니다. CGAffineTransform.translation 등을 사용하여 사용자 지정 전환을 만들고 전환으로 컨트롤러를 애니메이션 한 다음 navigationController의 viewController에 추가해야합니다.


답변

스위프트 3

        let vc0 : ViewController1 = ViewController1()
        let vc2: NavigationController1 = NavigationController1(rootViewController: vc0)
        self.present(vc2, animated: true, completion: nil)


답변

Swift 버전 : 내비게이션 컨트롤러에 내장 된 ViewController를 나타냅니다.

    override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    //  Identify the bundle by means of a class in that bundle.
    let storyboard = UIStoryboard(name: "Storyboard", bundle: NSBundle(forClass: SettingsViewController.self))

    // Instance of ViewController that is in the storyboard.
    let settingViewController = storyboard.instantiateViewControllerWithIdentifier("SettingsVC")

    let navController = UINavigationController(rootViewController: settingViewController)

    presentViewController(navController, animated: true, completion: nil)

}