Makalele
Makalele

Reputation: 7521

UIButton exceeding view controller without clipping to its bounds

In my app I'm using KYDrawerController library from here: https://github.com/ykyouhei/KYDrawerController

It works as expected, but I want to add an UIButton on the menu view controller (which is on top when opened), however it's clipped by view bounds. Best way I can explain this is by showing you a screenshot:

enter image description here

And here's how it should look like:

enter image description here

Button now has negative right constraint margin so it's position is correct, but how can I disable clipping?

In the menu view controller, which can you see on the foreground, I've added this code:

    self.navigationController?.navigationBar.clipsToBounds = false
    self.navigationController?.view.clipsToBounds = false
    self.view.clipsToBounds = false
    let elDrawer = self.navigationController?.parent as! KYDrawerController
    elDrawer.view.clipsToBounds = false
    elDrawer.displayingViewController?.view.clipsToBounds = false
    elDrawer.drawerViewController?.view.clipsToBounds = false
    elDrawer.displayingViewController?.view.clipsToBounds = false
    elDrawer.mainViewController.view.clipsToBounds = false
    elDrawer.inputViewController?.view.clipsToBounds = false
    elDrawer.splitViewController?.view.clipsToBounds = false

As you can see I've tried all possible ways to disable clipping, yet it's still clipped. How can I achieve this?

edit: Added hierachy view: enter image description here

I've also tried to run following test:

var view = arrowButton as UIView?
        repeat {
            view = view?.superview
            if let sview = view {
                if(sview.clipsToBounds){
                    print("View \(view) clips to bounds")
                    break
                }
                else{
                    print("View \(view) does not clip to bounds")
                }
            }
        } while (view != nil)

And it prints:

View Optional(>) does not clip to bounds

So looks like nothing is clipping yet it's clipped.

edit2: debug view hierarchy: enter image description here

Upvotes: 0

Views: 1746

Answers (2)

Duncan C
Duncan C

Reputation: 131418

We can't really tell what's going on because you don't show us the view hierarchy.

I suggest you write test code that starts at the button, walking up the superview hierarchy looking for a superview who's' clipsToBounds is true. Something like this:

var view = button as UIView?
repeat {
  view = view.superview
  if view?.superview.clipsToBounds ?? false == true {
    print("View \(view) clips to bounds")
    break
} while view != nil

Then you'll know which view is clipping, and you can fix it witout the "shotgun" approach you're using.

EDIT:

I'm not sure why you are getting such strange debug messages. I suggest adding unique tag numbers to all the button's superviews, and then using code like this:

override func viewDidAppear(_ animated: Bool) {
  var view = button as UIView?
  repeat {
    view = view?.superview
    if let view = view {
      let tag = view.tag
      let description = (tag == 0) ? view.debugDescription : "view w tag \(tag)"
      if(view.clipsToBounds){
        print("View \(description) clips to bounds")
        break
      }
      else{
        print("View \(description) does not clip to bounds")
      }
    }
  } while (view != nil)

}

Post ALL the output from that debug code so we can see the entire view hierarchy you're dealing with.

Upvotes: 0

Makalele
Makalele

Reputation: 7521

Yay, I've found the solution:

self.navigationController?.view.subviews[0].clipsToBounds = false

old code is not needed.

UINavigationTransitionView (it's Apple private class) was the one responsible with clipToBounds turned on.

Upvotes: 3

Related Questions