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

Problem to present in Navigation Controller #2

Closed
fabriciomasiero opened this issue Jul 18, 2017 · 11 comments
Closed

Problem to present in Navigation Controller #2

fabriciomasiero opened this issue Jul 18, 2017 · 11 comments

Comments

@fabriciomasiero
Copy link

Hi, im attempting to present the CoachMark in NavigationController!

And i write this:
self.navigationController?.view.addSubview(coachmark)
coachmark.translatesAutoresizingMaskIntoConstraints = false
coachmark.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
coachmark.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
coachmark.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
coachmark.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true

But the console show me this error: *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutXAxisAnchor:0x60800126f880 "CoachMarks.CoachmarkView:0x7fe78bee92f0.left"> and <NSLayoutXAxisAnchor:0x60800126f900 "UIView:0x7fe78bee8df0.left"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'

Whats going on? Thanks

@pNre
Copy link
Owner

pNre commented Jul 23, 2017

Have you tried placing the coachmark view inside the view of your UINavigationController's topViewController?

@fabriciomasiero
Copy link
Author

fabriciomasiero commented Jul 26, 2017

Hi, im tried to present in topViewController and app dont crash anymore, awesome!

But im want to present coachmark in my NavigationBar too, like coachmarking my barbutton items...

Check this image on attach

My code:

self.navigationController?.topViewController?.view.addSubview(coachmark) coachmark.translatesAutoresizingMaskIntoConstraints = false coachmark.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true coachmark.topAnchor.constraint(equalTo: view.topAnchor).isActive = true coachmark.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true coachmark.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true

self.navigationItem.rightBarButtonItems = [self.btnBarSearch, self.btnBarFilter] coachmark.textLabel.textColor = .white coachmark.textLabel.text = "👋 this is a little example app showcasing some coach marks" coachmark.present(in: view, from: CGRect(x: self.btnBarFilter.buttonFrame().origin.x, y: 0, width: 40, height: 40), focusingOnElement: false)

Thanks bro

simulator screen shot 26 de jul de 2017 19 03 17

@pNre
Copy link
Owner

pNre commented Jul 29, 2017

Got it, here:

self.navigationController?.view.addSubview(coachmark)

you are adding the coach mark as a subview of navigationController?.view.

And here:

coachmark.translatesAutoresizingMaskIntoConstraints = false
coachmark.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
coachmark.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
coachmark.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
coachmark.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true

you are installing layout constraints between the coach mark and your view controller view.

To fix your issue just set the constraints between coachmark and navigationController?.view by writing something like this:

coachmark.translatesAutoresizingMaskIntoConstraints = false
coachmark.leftAnchor.constraint(equalTo: navigationController!.view.leftAnchor).isActive = true
coachmark.topAnchor.constraint(equalTo: navigationController!.iew.topAnchor).isActive = true
coachmark.bottomAnchor.constraint(equalTo: navigationController!.view.bottomAnchor).isActive = true
coachmark.rightAnchor.constraint(equalTo: navigationController!.view.rightAnchor).isActive = true

@fabriciomasiero
Copy link
Author

fabriciomasiero commented Jul 31, 2017

Ohh, its works very well!! Thank you!!

One more question here, I swear =D

Why are some white corners appearing? I already tried to change the background color and other things, but nothing stopped them from appearing. If I use in my navigationController.topView these same white corners do not appear!

simulator screen shot 31 de jul de 2017 15 18 08

Doesnt matter the position, look this

simulator screen shot 31 de jul de 2017 15 24 08

@pNre
Copy link
Owner

pNre commented Jul 31, 2017

This is probably because the from: CGRect param you're passing to coachmark.present(in:from:focusingOnElement:) is too small.

Try adding some margin to it, try something like this:

coachmark.present(in: view, from: CGRect(x: self.btnBarFilter.buttonFrame().origin.x, y: 0, width: 40, height: 40).insetBy(dx: -5, dy: -5), focusingOnElement: false)

@fabriciomasiero
Copy link
Author

Doesnt matter my insetBy, the white walkers (AKA white corners) continues appearing

@pNre
Copy link
Owner

pNre commented Jul 31, 2017

Can you upload an example project having this issue?

@fabriciomasiero
Copy link
Author

Yes, take a look

https://github.com/fabriciomasiero/CoachMarksExampleError

Please, use iPhone 6s, cause the present CGRect are with hand values

@pNre
Copy link
Owner

pNre commented Jul 31, 2017

Ok, I guess that's a bug. I'll push a fix as soon as possible.

@pNre
Copy link
Owner

pNre commented Aug 1, 2017

Let me know if 56fce70 fixes the issue

@fabriciomasiero
Copy link
Author

@pNre WORKS!!! Thanks bro!

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

2 participants