fortmarek / SwipeViewController

SwipeViewController is a Swift modification of RKSwipeBetweenViewControllers - navigate between pages / ViewControllers
MIT License
655 stars 46 forks source link

Insert an image in the middle of navigation bar (between swipe buttons) #22

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi, thank you so much for sharing this awesome project. I'm still an ios-app-developing beginner, I would like to insert an image between my two swipe buttons, is there possibly a way to do that? Thank you!

fortmarek commented 7 years ago

In SwipeViewController viewWillAppear function write this:

//Navigation View
        let navigationView = interfaceController.initNavigationView()
        let imageView = UIImageView(image: UIImage(named: "YellowHearts"))
        imageView.frame.size = CGSize(width: 20, height: 20)
        imageView.center = CGPoint(x: viewWidth / 2 - 50, y: navigationBarHeight / 2)
        navigationView.addSubview(imageView)

And in InterfaceController find line if buttonDelegate.equalSpaces {:

if buttonDelegate.equalSpaces {
                originX = buttonDelegate.x * CGFloat(button.tag) + width + buttonDelegate.offset - barButtonDelegate.barButtonItemWidth
                if button.tag == 1 {
                    originX -= buttonDelegate.offset
                }
                else {
                    originX += buttonDelegate.offset
                }
                width += buttonWidth
            }

Let me know if it works, so I can close this.

ghost commented 7 years ago

Thanks a lot, it worked! But when I set below code, the selection bar won't be right under the swipe buttons, how should I fix that?
setButtonsOffset(90, bottomOffset: 0)

fortmarek commented 7 years ago

How far away is it? Or can you send me a screenshot?

ghost commented 7 years ago

Here are the screenshots.

screen shot 2017-05-02 at 6 06 21 pm screen shot 2017-05-02 at 6 06 29 pm

fortmarek commented 7 years ago

And did it work before adding the image? If it did, the problem should definitely be something in InterfaceController, I would try to check if the setting of tags and button offsets are right, focus on the part here:

if buttonDelegate.equalSpaces {
                originX = buttonDelegate.x * CGFloat(button.tag) + width + buttonDelegate.offset - barButtonDelegate.barButtonItemWidth
                if button.tag == 1 {
                    originX -= buttonDelegate.offset
                }
                else {
                    originX += buttonDelegate.offset
                }
                width += buttonWidth
            }
ghost commented 7 years ago

Yes, it worked before adding the image.

fortmarek commented 7 years ago

I am sorry, the problem is with selectionBar, I will look into it later during today.

fortmarek commented 7 years ago

Mine works just fine with the adjustments I posted here, but just to be sure, could you send me your InterfaceController class and your implementation of SwipeViewController?