美文网首页
iOS Swift界面viewcontroller跳转

iOS Swift界面viewcontroller跳转

作者: Lee坚武 | 来源:发表于2022-07-13 16:17 被阅读0次
    本人亲测有效!更多交流可以家魏鑫:lixiaowu1129,公重好:iOS过审汇总,一起探讨iOS技术!
    

    iOS开发中界面跳转有两种方式,上下跳转和左右跳转。

    上下跳转_打开:
    let secondViewController = SecondViewController()  
    self.presentViewController(secondViewController, animated: true, completion: nil)  
    
    上下跳转_关闭:
    self.dismissViewControllerAnimated(true, completion: nil)  
    
    左右跳转_打开:

    (将新的视图控制器PUSH到navigationController中,相当于入栈操作)

    let secondViewController = SecondViewController()  
    self.navigationController!.pushViewController(secondViewController, animated: true)  
    
    左右跳转_关闭:

    (将当前视图控制器从导航视图控制器堆栈中移除,从而返回到了上一级界面)

    BACK_到上一级:

    let firstViewController = FirstViewController()  
    self.navigationController?.popViewControllerAnimated(true)  
    

    BACK_指定界面:

    // 获得视图控制器中的某一视图控制器  
    let viewController = self.navigationController?.viewControllers[0]  
    self.navigationController?.popToViewController(viewController as! UIViewController, animated: true)  
    

    BACK_根视图:

    self.navigationController?.popToRootViewControllerAnimated(true)  
    

    根视图的设置需要在AppDelegate中设置

    var window: UIWindow?  
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool  
    {  
        var firstViewController = FirstViewController()  
        var rootNavigationViewController = UINavigationController(rootViewController: firstViewController)  
              
        self.window!.rootViewController = rootNavigationViewController  
              
        return true  
    } 
    
    手写界面
    var vc = ViewController() 
    self.presentViewController(vc, animated: true, completion: nil)
    
    storyboard制作页面
    var sb = UIStoryboard(name: "Main", bundle:nil)  
    var vc = sb.instantiateViewControllerWithIdentifier("VC") as ViewController
    //VC为该界面storyboardID,Main.storyboard中选中该界面View,Identifier inspector中修改
    self.presentViewController(vc, animated: true, completion: nil)
    
    
    self.performSegueWithIdentifier("VC", sender: nil)
    

    本文由mdnice多平台发布

    相关文章

      网友评论

          本文标题:iOS Swift界面viewcontroller跳转

          本文链接:https://www.haomeiwen.com/subject/jfltirtx.html