【问题标题】:SWRevealViewController - Prevent Interacting With The Back ViewSWRevealViewController - 防止与后视图交互
【发布时间】:2016-10-03 14:32:26
【问题描述】:

当使用 SWRevealViewController 时,我不想让用户与打开侧边菜单的视图交互。侧边菜单打开后,我希望能够与该菜单视图进行交互,而不是另一个。

有什么帮助吗?

【问题讨论】:

    标签: ios objective-c swift swrevealviewcontroller


    【解决方案1】:

    好吧,我已经在 SWRevealViewController 上工作了一段时间了 所以你需要将你的frontViewController添加为SWRevealViewControllerDelegate,然后实现这个功能

    func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)
    

    frontViewController 向左或向前移动时会通知您

    这是 Swift 代码

    在你的frontViewController中你需要添加

    class FrontViewController: UIViewController, SWRevealViewControllerDelegate
     {
    override func viewDidLoad() {
    super.viewDidLoad()
    self.revealViewController().delegate = self;
     }
    

    //您的代码//

    func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
            if(position == FrontViewPosition.Left)
            {
                self.view.userInteractionEnabled = true;
                self.navigationController?.navigationBar.userInteractionEnabled = true;
            }else
            {
                self.view.userInteractionEnabled = false;
                self.navigationController?.navigationBar.userInteractionEnabled = false;
    
            }
    }
    

    //已编辑

    这是 Objective C 代码

    class FrontViewController: UIViewController <SWRevealViewControllerDelegate>
    

    在viewDidLoad中需要添加

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.revealViewController.delegate = self;
    }
    

    //您的代码//

    - (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
    {
        if(position == FrontViewPositionLeft)
        {
            self.view.userInteractionEnabled = NO;
            self.navigationController.navigationBar.userInteractionEnabled = NO;
        }else{
            self.view.userInteractionEnabled = YES;
            self.navigationController.navigationBar.userInteractionEnabled = YES;
        }
    }
    

    希望对你有帮助

    【讨论】:

    • 您好 @user5432778 如果我的回答确实解决了您的问题,您能否将我的回答标记为已接受,谢谢
    • 嘿,是的,这看起来会起作用。你能帮忙看看objective c版本吗?谢谢!
    • OK @user5432778,我会在几分钟内发布 Objective C 版本
    猜你喜欢
    • 2019-07-19
    • 2014-05-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 2017-05-17
    • 2015-07-01
    • 2011-03-20
    • 1970-01-01
    相关资源
    最近更新 更多