Giter Site home page Giter Site logo

Comments (8)

hongzhou85 avatar hongzhou85 commented on July 19, 2024

Same i cannot detect any gestures or IBAction in the parallax header. How do intercept the touch?

from mxparallaxheader.

jj-12 avatar jj-12 commented on July 19, 2024

Same here. This would be an awesome thing to know. Thanks!

from mxparallaxheader.

hongzhou85 avatar hongzhou85 commented on July 19, 2024

I have achieved it by storing a reference of the tableViewController or scrollViewController or collectionViewController in the headerView. Then set the buttons' touchGestureRecognizer target to your reference and have the function in there to handle the action. It should works that way.

from mxparallaxheader.

hongzhou85 avatar hongzhou85 commented on July 19, 2024

For the header:

class HeaderView : UIVIewController {
  @IBOutlet weak var button : UIButton!
  var parent: UIViewController?  // Usually your tableview/scrollview/collectionview

  override viewDidLoad() {
    let tapGestureRecognizer = UITapGestureRecognizer(target:self.parent!, action:#selector(ParentViewCollection.actionGesture(_:)))
        button.userInteractionEnabled = true
        button.addGestureRecognizer(tapGestureRecognizer)
  }
}

For the "parent":

class ParentViewController : UIViewController {
   let header : HeaderView = HeaderView()

   override viewDidLoad() {
        header.parent = self
        self.collectionView!.parallaxHeader.view = header.view
        self.collectionView!.parallaxHeader.height = headerHeight
        self.collectionView!.parallaxHeader.mode = MXParallaxHeaderMode.Fill
        self.collectionView!.parallaxHeader.minimumHeight = 0
   }

   func actionGesture(sender : UIGestureRecognizer) {
        // here you can do what you want with the button
    }
}

from mxparallaxheader.

maxep avatar maxep commented on July 19, 2024

This is a good approach @hongzhou85. Instead of setting a parentproperty, you can create a delegate and call that delegate on gesture.
Another approach would be to create a floating view in your view controller from storyboard, then to attach this floating view to your parallax header. This would allow you to trigger segues directly from your header view.

from mxparallaxheader.

jj-12 avatar jj-12 commented on July 19, 2024

Great, the floating view seems to work pretty well. Thanks guys!

from mxparallaxheader.

AmruthaMurthy1512 avatar AmruthaMurthy1512 commented on July 19, 2024

Great, the floating view seems to work pretty well. Thanks guys!

Any code snippet how you added a floating view. My requirement is that I need to add back button on Top of Parallex header view.

from mxparallaxheader.

AmruthaMurthy1512 avatar AmruthaMurthy1512 commented on July 19, 2024

This is a good approach @hongzhou85. Instead of setting a parentproperty, you can create a delegate and call that delegate on gesture.
Another approach would be to create a floating view in your view controller from storyboard, then to attach this floating view to your parallax header. This would allow you to trigger segues directly from your header view.

Any code snippet how you added a floating view. My requirement is that I need to add back button on Top of Parallex header view.

from mxparallaxheader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.