如何在ios中推出swreveal视图控制器中的pop?

时间:2016-11-26 04:32:05

标签: ios objective-c swrevealviewcontroller

我有像Facebook这样的应用程序。我想在swreveal视图控制器中推送和弹出。怎么能实现这个?检查以下图片。

enter image description here

任何帮助将不胜感激。

4 个答案:

答案 0 :(得分:4)

我会有一个这样的故事板:

enter image description here

在LoginViewController中:

    @IBAction func skip(_ sender: Any) {
    // Show dashboard

    let sb = UIStoryboard(name: "Main", bundle: nil)
    let controller = sb.instantiateViewController(withIdentifier: "DashboardNavigationController")

    revealViewController().setFront(controller, animated: true)
}

@IBAction func validateUser(_ sender: Any) {
    // show profile

    // Here test for valid user name and password
    // If OK
    let sb = UIStoryboard(name: "Main", bundle: nil)
    let dashboardNC = sb.instantiateViewController(withIdentifier: "DashboardNavigationController") as! UINavigationController

    let profileVC = sb.instantiateViewController(withIdentifier: "ProfileViewController")
    dashboardNC .pushViewController(profileVC, animated: false)

    revealViewController().setFront(dashboardNC, animated: true)
}

@IBAction func dismissKeyboard(_ textField: UITextField) {
    textField.resignFirstResponder()
}

在MenuTableViewController(SideMenu)中:

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

    // ...
    let dashboardNC = revealViewController().frontViewController as! UINavigationController
    let nc = revealViewController().frontViewController as! UINavigationController
    let vc = nc.topViewController

    if !(vc is ProfileViewController) {
        // Instantiate controller from story board
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let controller = sb.instantiateViewController(withIdentifier: "ProfileViewController")
        dashboardNC.pushViewController(controller, animated: false)
    }

    // Push it with SWRevealViewController
    revealViewController().pushFrontViewController(dashboardNC, animated: true)
}

DashboardViewController:

class DashboardViewController: UIViewController {

@IBOutlet weak var revealButton: UIBarButtonItem!
@IBOutlet weak var rightButton: UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad()

    revealButton.target = revealViewController()
    revealButton.action = #selector(SWRevealViewController.revealToggle(_:))

    rightButton.target = revealViewController()
    rightButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))

    revealViewController().tapGestureRecognizer()
    revealViewController().panGestureRecognizer()

    revealViewController().rearViewRevealOverdraw = 0
    revealViewController().rightViewRevealOverdraw = 0
}

不是Objective-C但你可以轻松翻译!

答案 1 :(得分:0)

在您的app委托中,您必须通过windowViewController窗口管理Login / Dashboard。

第1步: 在AppDelegate中编写方法,请调用示例setupRootVC()

func setupRootVC(){
    if userIsLoggedIn{
       window.rootViewController = yourSWRevealControllerObj
    }else{
       window.rootViewController = yourLoginControllerObj
    }
}

第2步:setupRootVC()方法调用didFinishLaunchingWithOptions方法。

第3步:在LoginVC中,用户登录后成功调用AppDelegate的setupRootVC()方法。

第4步:确保frontViewController的{​​{1}}位于SWRevealController内,以便您可以推送并弹出它。

我建议您详细了解iOS应用架构以及UINavigationControllerrootViewController的工作原理。 希望有所帮助。

答案 2 :(得分:0)

如果你想从swreveal推送到任何控制器

UIStoryboard*Storyboard=[AppDelegate storyBoardType];
    yourController  *your=(yourController*)[Storyboard instantiateViewControllerWithIdentifier:@"yourControllerId"];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: your];

    [navController setViewControllers: @[your] animated: YES];
    [self.revealViewController setFrontViewController:navController];
    [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];

        }

从任何控制器到swreveal视图控制器,您必须在操作中添加此行单击

 [self.revealViewController revealToggleAnimated:YES];

答案 3 :(得分:0)

您可以使用UINavigationController的方法:

- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);

但请注意,它设置了整个导航控制器堆栈。 所以你可能不得不采取当前的视图控制器状态 来自物业

@property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers; 

分配新的

NSMutableArray *controllers = [NSMutableArray arrayWithArray:self.navigationController viewControllers];

[controllers addObject:VC1];
[controllers addObject:VC2];
[controllers addObject:VC3];
[self.navigationController setViewControllers:controllers animated:YES];