1

I am currently trying to make it so that when the user uses my app, the user will see a animation view that says, "Slide Left to Bring out Menu!" I want this view to not be shown once the user slides left to bring out the menu.

Here are some screenshots/diagrams showing what I mean:

Demonstration

Demonstration2

I have tried some code that I have looked up on the internet such as(animView being the view containing the label, "Slide Left to Bring Out Menu"), however this solution did not work:

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

        animView.isHidden = true

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

EDIT: I have tried the proposed solutions in the comments below, however I am not sure as to how to use this. Below is what I have tried:

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

            animView.isHidden = true


        default:
            break
        }
    }

FULL CODE IN CLASS ASSOCIATED WITH 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.
}

}
Rajat Khare
  • 522
  • 8
  • 26
  • For showing once on label, you may use sqlite to remember user that user slide. Here is an article for recognizing slide out : https://github.com/John-Lluch/SWRevealViewController/issues/492 – Jacky Shek Feb 07 '17 at 08:22
  • @JackyShek could you give some more information on how to do this. I would appreciate it a lot. I am still very confused. – Rajat Khare Feb 07 '17 at 20:16
  • 1
    For the first problem, you may use the `didMoveToPosition` method of SWreveal for recognizing that user swiped the menu. Check it if `revealController.frontViewPosition == FrontViewPositionRight` then hide the label and saving a record in SQLite that user swiped the left-side menu. And check the label need to show or not with SQLite record in `viewDidLoad`. You may use FMDB: https://github.com/ccgus/fmdb – Jacky Shek Feb 08 '17 at 01:23
  • 1
    For the second problem, it should be 2 subviews (label in a subviews and the webview is another subviews). You may learn it in http://stackoverflow.com/questions/4631878/how-to-set-iphone-ui-view-z-index – Jacky Shek Feb 08 '17 at 01:26
  • @JackyShek So, I tried out your solution for the first problem, however, when I use `func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition) { if (revealController.frontViewPosition == FrontViewPosition.right){ animView.isHidden = true } }` – Rajat Khare Feb 08 '17 at 20:44
  • ... it doesn't work. Do you have any ideas as to why it doesn't? – Rajat Khare Feb 08 '17 at 20:45
  • did you use `SWRevealViewControllerDelegate` in your view controller? like: http://stackoverflow.com/questions/22275911/swrevealviewcontroller-close-rear-view-when-tapping-front-view – Jacky Shek Feb 09 '17 at 01:25
  • @JackyShek yes I have used SWRevealViewControllerDelegate in my viewcontroller. I was wondering if you could view my last edit(Has all of my code in the class) – Rajat Khare Feb 11 '17 at 06:27
  • If there is no one to help you before GTM 2017-2-10 18:00. I will copy the code and try it after GTM 12-2-10 16:00. Before that time. Try hide animateView in the ***ViewDidAppear*** of reveal view. – Jacky Shek Feb 11 '17 at 07:13
  • You forget to put ***self.revealViewController().delegate = self***, it cannot control the 'revealViewController' when you do not give delegate – Jacky Shek Feb 11 '17 at 15:48
  • @JackyShek perhaps you could try and copy the code? I have tried both of your solutions, however, none have worked yet – Rajat Khare Feb 12 '17 at 01:03
  • @JackyShek any ideas? – Rajat Khare Feb 12 '17 at 19:18
  • I need more time for it. First, don't `private` the `func revealController`. second, add `self.revealViewController().delegate = self` in `ViewDidAppear ` at the front view. – Jacky Shek Feb 13 '17 at 01:25
  • @JackyShek Thanks dude! Finally got it to work with your solution. Feel free to write an answer. Will accept and vote it up – Rajat Khare Feb 13 '17 at 03:22
  • @JackyShek now I just need it so that when the user sees it the first time and does the action it will go away – Rajat Khare Feb 13 '17 at 03:23
  • Ok, that's great. I will improve the answer when i have time. – Jacky Shek Feb 13 '17 at 03:53

1 Answers1

1

For just showing the label on the first time (The First Problem):

You may use the didMoveToPosition method of SWreveal for recognizing that user swiped the menu. And Check that if revealController.frontViewPosition == FrontViewPositionRight then hide the label and saving a record in SQLite that user swiped the left-side menu already. And check the label need to show or not with SQLite record in ViewDidLoad or ViewWillAppear. You may use FMDB: github.com/ccgus/fmdb

For UILabel position (The Second Problem):

It should be 2 subviews (webview is the first subviews and the label is another subviews). You may learn it in stackoverflow.com/questions/4631878/

Remember that:

First, don't private the revealController function which the delegate cannot be worked.Also add SWRevealViewControllerDelegate

Second, you forget to put self.revealViewController().delegate = self in ViewDidAppear

Community
  • 1
  • 1
Jacky Shek
  • 953
  • 1
  • 11
  • 35
  • I am having some trouble in making the uiwebview's subview slide up on top of the preexisting uiview. I also would like it if you could help me in how I can store the data in SQLite. I am not sure of how to use this. Thanks – Rajat Khare Feb 14 '17 at 08:27
  • What is the problem that you are facing?? For using SQLite, you can use the FMDB library. here is the tutorial: http://www.appcoda.com/fmdb-sqlite-database/ – Jacky Shek Feb 14 '17 at 16:46
  • Hi I was wondering if you could check out my latest question and see if you have an idea as to how to fix this problem. Thanks – Rajat Khare Feb 17 '17 at 05:36
  • Sorry i don't get your meaning on `trouble in making the uiwebview's subview slide up on top of the preexisting uiview`. Please tell me more specifically. – Jacky Shek Feb 17 '17 at 05:44
  • I got the problem to work with the sliding up animation by adding the self.view.layoutIfNeeded() at the end of the function – Rajat Khare Feb 17 '17 at 06:09
  • If you don't mind, I would appreciate it if you could check my last question posted, and perhaps if you know tell me what to fix. You seem pretty knowledgeable in swift so I would really appreciate it. – Rajat Khare Feb 17 '17 at 06:10