简体   繁体   中英

Hold down to view video like snapchat in swift

So I have a TableView that for each cell a user can hold down to view a video/image. The holding down part works but when I release it doesn't go back to the TableView . Heres the code for presenting the view with the video/image:

func playVideo() {
    // get path and url of movie
    let path = NSBundle.mainBundle().pathForResource("static2", ofType:"mov")
    println(path)
    let url = NSURL.fileURLWithPath(path!)
    var moviePlayer = MPViewController()//took out video handling right now so this is just basically a regular view controller
    moviePlayer.navController = self.navigationController
    // construct the views
    moviePlayer.addGestRecognizer()

    self.navigationController.pushViewController(moviePlayer, animated: true)
}

and then I have this gesture recognizer added to the view cell:

let singleTap = UILongPressGestureRecognizer(target: self, action: Selector("tapped:"))
self.addGestureRecognizer(singleTap)

and here is the "tapped:" function:

func tapped(gestureRecognizer:UIGestureRecognizer){
    println("held down")
    if gestureRecognizer.state == UIGestureRecognizerState.Began {
        playVideo()
    }
    if gestureRecognizer.state == UIGestureRecognizerState.Ended {
        println("hold ended")
        self.navigationController.popViewControllerAnimated(true)
    }
    //playVideo()
}

for some reason once I push the view controller onto the main navigationController I no longer get the "hold ended". How can I set this up so it works exactly like snapchat?

This is not a solution for what you're asking but another idea, you might want to think about presenting the media files with a UIView instead of a UIViewController .

Hope that helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM