打开SWRevealController菜单后如何使View不可见 - Swift

时间:2017-02-07 05:03:55

标签: ios swift xcode swrevealviewcontroller

我目前正在尝试这样做,以便当用户使用我的应用程序时,用户将看到一个动画视图,其中显示,"向左滑动以显示菜单!"我希望一旦用户向左滑动以显示菜单,就不会显示此视图。

以下是一些截图/图表,显示了我的意思:

Demonstration

Demonstration2

我已经尝试了一些我在互联网上查找的代码,例如(animView是包含标签的视图,&#34;向左滑动以显示菜单&#34;)但是这个解决方案不起作用:< / p>

if (self.revealViewController().frontViewPosition != FrontViewPosition.left) {

        animView.isHidden = true

    }
    else if (self.revealViewController().frontViewPosition == FrontViewPosition.left){
        animView.isHidden = false
    }

编辑:我在下面的评论中尝试过提议的解决方案,但是我不确定如何使用它。以下是我的尝试:

func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition) {
        switch(position){
        case FrontViewPosition.leftSideMost: break

            animView.isHidden = true


        default:
            break
        }
    }

与ANIMVIEW相关的完整代码

import Foundation
import UIKit
import SVProgressHUD
import Canvas

class WebViewHome: UIViewController, UIWebViewDelegate, SWRevealViewControllerDelegate{


@IBOutlet weak var WebViewTst: UIWebView!
@IBOutlet weak var animView: CSAnimationView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.navigationBar.topItem!.title = "Home"

    let URL = NSURL(string: "https://gunnoracle.com/")
    WebViewTst.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest)

    let topSpace = -190
    let bottomSpace = -3045
    let leftSpace = -40
    let rightSpace = -40
    WebViewTst.scrollView.contentInset = UIEdgeInsets(top: CGFloat(topSpace), left: CGFloat(leftSpace), bottom: CGFloat(bottomSpace), right: CGFloat(rightSpace))
    WebViewTst.scrollView.bounces = false

    WebViewTst.scrollView.maximumZoomScale = 1.0
    WebViewTst.scrollView.minimumZoomScale = 1.0

    WebViewTst.delegate = self



}

private func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition) {

    if (revealController.frontViewPosition == FrontViewPosition.leftSide){




    }

    else{


    }


}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {

    switch navigationType {

    case .linkClicked:

        let topSpace = -170
        let bottomSpace = -2840
        let leftSpace = -40
        let rightSpace = -40

        animView.startCanvasAnimation()
        WebViewTst.scrollView.contentInset = UIEdgeInsets(top: CGFloat(topSpace), left: CGFloat(leftSpace), bottom: CGFloat(bottomSpace), right: CGFloat(rightSpace))
        WebViewTst.scrollView.bounces = false

        WebViewTst.scrollView.maximumZoomScale = 1.0
        WebViewTst.scrollView.minimumZoomScale = 1.0

        WebViewTst.delegate = self

    default:
        break
    }
    return true
}

func webViewDidStartLoad(_ webView: UIWebView) {

    SVProgressHUD.show(withStatus: "Loading...")
    SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)
    SVProgressHUD.setRingThickness(1.0)
    NSLog("Webview has started loading")
}

func webViewDidFinishLoad(_ webView: UIWebView) {
    SVProgressHUD.dismiss()
    NSLog("Webview has successfully loaded")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

1 个答案:

答案 0 :(得分:1)

仅在第一次显示标签时(第一个问题)

您可以使用SWreveal的didMoveToPosition方法识别用户刷过菜单。并检查是否revealController.frontViewPosition == FrontViewPositionRight然后隐藏标签并在SQLite中保存记录,用户已经刷过左侧菜单。并使用ViewDidLoadViewWillAppear中的SQLite记录检查标签是否需要显示。您可以使用FMDB:github.com/ccgus/fmdb

对于UILabel职位(第二个问题):

它应该是2个子视图(webview是第一个子视图,标签是另一个子视图)。您可以在stackoverflow.com/questions/4631878/

中了解相关信息

请记住

首先 ,不要private代理无法工作的revealController函数。还要添加SWRevealViewControllerDelegate

第二次 ,您忘记将self.revealViewController().delegate = self放入ViewDidAppear