0

UIButton TouchUpInside only fires when tapping on the first "x". It's like the tappable area has shrunk even though I've not set this explicitly. Image from UI Inspector

The UIButton is created in IB initially and wired up to an IBOutlet but then in code I set the button up in the view's init() method.

    btnHideView?.frame = CGRectMake((9.0*deviceWidth()/16.0) - 60, (viHeaderView!.frame.size.height - 30.0)/2.0, 60, 30)
    btnHideView?.setTitle("xxxxxxxxx", forState: UIControlState.Normal)
    btnHideView?.addTarget(self, action: Selector("hideView"), forControlEvents: UIControlEvents.TouchUpInside)
    btnHideView?.tintColor = UIColor.whiteColor()
    btnHideView?.layer.borderWidth = 1.0
    btnHideView?.layer.borderColor = UIColor.whiteColor().CGColor

Edit: Simulator with Color Blended Layers

enter image description here

empo
  • 1,133
  • 5
  • 21
  • 41
  • Run your app in the simulator, and use "Color blended layouts" option from the menu. Then post back your result. By the way, why not using constraints to set your button position ? `deviceWidth()` sounds like an awful method – Antzi Nov 03 '15 at 21:54
  • @Antzi - image added. I'm new to iOS and was advised by an experienced developer that it's better to position UI elements in code instead of using constraints (something about having more control over where elements are drawn). – empo Nov 03 '15 at 22:12
  • Have you asked the experienced developer for help with this problem? ;^) – rob mayoff Nov 03 '15 at 22:30
  • @robmayoff yep...and now I'm here. – empo Nov 03 '15 at 22:51
  • 1
    Typically this sort of problem has one of two causes: the button is partially outside the bounds of its superview (or some ancestor view), or some other view is partially overlaying the button. Use Xcode's [view hierarchy debugger](http://stackoverflow.com/a/26052806/77567) to check for those scenarios. – rob mayoff Nov 03 '15 at 23:01
  • You may have 'more control' doing your layouts in code, but how much control do you really need for a button that only needs 4 constraints? – Beau Nouvelle Nov 03 '15 at 23:13
  • @empo: (iPad *2 + iPad Pro * 2) * 2 + iPhone 5*2 + iPhone 4S*2 + iPhone 6 * 2 + iPhone 6+ *2 That's 16 form factors if you want to handle all device with all orientation + split screen. There is no way you can achieve that without constraints. It's ok if you are just targeting one or two form factors tho. – Antzi Nov 03 '15 at 23:19
  • @empo All the red part should be clickable. I cannot find any reason why not, sorry – Antzi Nov 03 '15 at 23:22
  • Guys, I'm on a learning curve. I appreciate your comments regarding the approach taken, but right now, I just need to fix the problem in hand. – empo Nov 03 '15 at 23:24
  • The approach you have taken may be the cause for your issues. The sizing may be off somehow, which is what could be causing problems with the tappable area. – Beau Nouvelle Nov 03 '15 at 23:34

0 Answers0