Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you grab clicked button's frame? #8

Open
robmontesinos opened this issue Aug 22, 2017 · 1 comment
Open

How do you grab clicked button's frame? #8

robmontesinos opened this issue Aug 22, 2017 · 1 comment

Comments

@robmontesinos
Copy link

I've implemented BMB successfully in my app. What I'd like to do is capture the clicked button's frame as the origination for an animated view controller transition.

I've implemented BoomDelegate.

func boomMenuButton(_ bmb: BoomMenuButton, didClickBoomButtonOfBuilder builder: BoomButtonBuilder, at index: Int) {
        loggingPrint(bmb.frame)
        loggingPrint(builder.imageFrame)
        
        let rect = builder.imageFrame
        let currentRect = convert(rect, to: bmb.superview)
        
        loggingPrint(currentRect)
    }
}

This delegate method returns the following in the console:

HeaderView.swift boomMenuButton(:didClickBoomButtonOfBuilder:at:)[315]: (317.0, 8.0, 50.0, 50.0)
HeaderView.swift boomMenuButton(
:didClickBoomButtonOfBuilder:at:)[316]: (10.0, 10.0, 30.0, 30.0)
HeaderView.swift boomMenuButton(_:didClickBoomButtonOfBuilder:at:)[317]: (10.0, 10.0, 30.0, 30.0)

This return is not giving me anything useful. Any help would be appreciated. Thank you.

@robmontesinos
Copy link
Author

robmontesinos commented Aug 23, 2017

I wound up temporarily solving this situation by exposing BoomMenuButton property "endPositions" by changing private keyword to public. The code below wound up working for me:

    // MARK: - BoomDelegate
    func boomMenuButton(_ bmb: BoomMenuButton, didClickBoomButtonOfBuilder builder: BoomButtonBuilder, at index: Int) {
        let buttonMenuFrame = bmb.frame
        let buttonEndPoint = bmb.endPositions[index]
        let buttonFrame = CGRect(x: buttonEndPoint.x - (0.5 * buttonMenuFrame.width),
                                 y: buttonEndPoint.y - (0.5 * buttonMenuFrame.height - Dimensions.bannerHeight.rawValue),
                                 width: buttonMenuFrame.width,
                                 height: buttonMenuFrame.height)
        
        buttonClickedFrame = buttonFrame
    }

buttonClickedFrame can now be referenced by transition manager.

It would be great if the library also exposed endPositions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant