presentViewController i wyświetlanie paska nawigacji

Mam hierarchię kontrolera widoku i kontroler na górze jest wyświetlany jako modalny i chciałbym wiedzieć, jak wyświetlić pasek nawigacyjny podczas korzystania z

'UIViewController:presentViewController:viewControllerToPresent:animated:completion'

Docs for 'presentViewController: animated: completion:' note:

' na iPhonie i iPodzie touch prezentowany widok jest zawsze Pełny ekran. Na iPadzie, prezentacja zależy od wartości w modalPresentationStyle property.'

Dla 'modalPresentationStyle', docs powiedz:

Styl prezentacji określa sposób wyświetlania modalnie prezentowanego kontrolera widoku na ekranie. Na iPhonie i iPodzie touch Kontrolery widoku modalnego są zawsze prezentowane na pełnym ekranie, ale na iPadzie istnieje kilka różnych opcji prezentacji.

Czy istnieje sposób, aby upewnić się, że pasek nawigacji jest widoczny pod paskiem stanu, gdy kontrola widoku się wyświetli? Czy powinienem interpretować doc jako, że nie masz żadnych opcji iPhone/iPod i tylko na iPad?

Wcześniej używałem 'UIViewController:presentModalViewController:animated', które działało dobrze, ale od iOS 5.0 API zostało przestarzałe, więc przełączam się na nowy.

Wizualnie, chcę, aby nowy kontroler wsunął się od dołu ekranu, tak jak robiło to stare API.

[uaktualnienie kodem]:

// 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];
Author: Raheel Sadiq, 2012-03-15

12 answers

Prawdą jest, że jeśli prezentujesz kontroler widoku modalnie na iPhonie, zawsze będzie on prezentowany na pełnym ekranie, bez względu na to, jak prezentujesz go na kontrolerze widoku górnego kontrolera nawigacyjnego lub w inny sposób. Ale zawsze możesz pokazać pasek nawigacji w ten sposób:

Zamiast modalnie prezentować kontroler widoku przedstaw kontroler nawigacji modalnie z ustawionym głównym kontrolerem widoku jako kontroler widoku:

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:^{

                        }];

Powinieneś zobaczyć nawigację Pasek, gdy widok jest wyświetlany modalnie.

 171
Author: Manish Ahuja,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-18 15:00:25

Swift 3.0/4.0

Nawigacja:

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

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

Powrót:

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

Swift 2.0

Nawigacja:

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

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

Powrót:

self.dismissViewControllerAnimated(true, completion: nil)
 26
Author: Tal Zion,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-16 07:07:51

Możesz użyć:

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

Powrót (chyba):

[self.navigationController popToRootViewControllerAnimated:YES];
 22
Author: marrop,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-06 20:01:17

Miałem ten sam problem na ios7. Zadzwoniłem do selektora i działało zarówno na ios7, jak i 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: ^ {

    }];
}
 2
Author: Mohammad Parvez,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-29 17:12:46

Wszystko, co robi [self.navigationController pushViewController:controller animated:YES];, to animowanie przejścia i dodawanie go do stosu kontrolerów nawigacyjnych oraz innych fajnych animacji paska nawigacyjnego. Jeśli nie zależy ci na animacji paska, to ten kod powinien działać. Pasek pojawia się na nowym kontrolerze, a ty dostajesz interaktywny gest pop!

//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.

Edit: Przepraszamy, presentViewController wypełni cały ekran. Będziesz musiał dokonać niestandardowego przejścia, z CGAffineTransform.tłumaczenie Czy coś, animować kontroler z przejściem, a następnie dodać go do kontrolerów ViewController navigationController.

 1
Author: Ignat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-21 16:59:43

Swift 3

        let vc0 : ViewController1 = ViewController1()
        let vc2: NavigationController1 = NavigationController1(rootViewController: vc0)
        self.present(vc2, animated: true, completion: nil)
 1
Author: BennyTheNerd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-04 16:57:45

Jedno rozwiązanie

DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil                                                                                 
                                        bundle:[NSBundle mainBundle]];  

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
navController.modalPresentationStyle = UIModalPresentationCurrentContext;



[self.navigationController presentViewController:navController 
                                        animated:YES 
                                        completion:nil];
 0
Author: Yatin Sarbalia,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-03-15 18:09:28

Jeśli nie ustawiono właściwości modalPresentationStyle (jak uimodalpresentationformsheet), pasek nawigacji będzie zawsze wyświetlany. Aby zapewnić, zawsze rób

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

To zawsze wyświetli pasek nawigacji.

 0
Author: rakeshNS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-20 11:39:00

Jeśli używasz NavigationController w Swift 2.x

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let targetViewController = storyboard.instantiateViewControllerWithIdentifier("targetViewControllerID") as? TargetViewController
self.navigationController?.pushViewController(targetViewController!, animated: true)
 0
Author: Ego Slayer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-07 06:53:15

Spróbuj tego

     let transition: CATransition = CATransition()
    let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.duration = 1
    transition.timingFunction = timeFunc
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromRight
    self.view.window!.layer.addAnimation(transition, forKey: kCATransition)
    self.presentViewController(vc, animated:true, completion:nil)
 0
Author: tsinghan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-17 05:24:33

Wersja Swift : To prezentuje ViewController, który jest osadzony w kontrolerze nawigacyjnym.

    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)

}
 0
Author: ioopl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-19 18:49:58

Używam tego kodu. Działa dobrze w iOS 8.

MyProfileEditViewController *myprofileEdit=[self.storyboard instantiateViewControllerWithIdentifier:@"myprofileeditSid"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myprofileEdit];
[self presentViewController:navigationController animated:YES completion:^{}];
 0
Author: Anil Prasad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-25 23:33:21