How to debug who is eating my touches in UIKit?

xcode symbolic breakpoint
swift detect touch on uiview
xcode symbolic breakpoint condition
xcode breakpoint when variable changes
xcode breakpoint expression
xcode set breakpoint in framework
add breakpoint xcode

I can't figure out why tapping on text fields and buttons in my view is not working. I've checked all the obvious things like whether userInteractionEnabled is set to YES, whether a gesture recognizer is installed, and if there is an invisible view in the foreground.

Is there a best practice in iOS for tracing a touch from when it first appears to where it gets consumed?


Both answers were helpful. During the course of my investigation I learned that if a subview is outside of its parent's bounds, even if the parent is not clipping subviews, the subview will not receive events. I printed out the chain of superviews from the text field that was not getting touches, and I saw that one of those views had a height of 0. I put in some constraints to stretch it out, and my problem was solved.

You can subclass UIWindow and override -[UIWindow sendEvent]:, then when it is called, use -[UIWindow hitTest:withEvent:] to test which view will receive the event.

You can then call -[UIView recursiveDescription] to print some debug information help you understand why that view received the touch event.

Remember to call [super sendEvent:] when you are done.

For those who use Storyboard and want to know how can we change the main application window class:

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow? = TestWindow()
    // ....

Just provide the default value for AppDelegate's window var. When the app is launched the UIApplicationMain will instantiate a delegate and ask it for the window. If the window is nil it will create a new one automatically. But if we provide a default value here, it will be used all over the app.

Handling Touches in Your View, There are two ways to handle touch events yourself. Use gesture recognizers to track the touches; see Handling UIKit Gestures. Track the touches directly in  9 How to debug who is eating my touches in UIKit? Dec 27 '17. 8 How to set UITextField height? Aug 8 '12.

You can debug that by using a symbolic breakpoint:

-[UIWindow sendEvent:] & po $arg3


<UITouchesEvent: 0x6000026fa6d0> timestamp: 179462 touches: {(
<UITouch: 0x7f84d6f10380> phase: Began tap count: 1 force: 0.000 
window: <UIWindow: 0x7f84d6d0ad10; frame = (0 0; 375 812); autoresize = W+H; 
gestureRecognizers = <NSArray: 0x600001aa8870>; layer = <UIWindowLayer: 0x6000014bd7e0>> view: <UIView: 0x7f84d6d0bff0; frame = (0 0; 375 812); 
autoresize = W+H; layer = <CALayer: 0x6000014bdc60>> location in window: {165.66665649414062, 232.33332824707031} previous location in window: 
{165.66665649414062, 232.33332824707031} location in view: {165.66665649414062, 
232.33332824707031} previous location in view: {165.66665649414062,232.33332824707031}

Touches, Presses, and Gestures, The three different iOS devices offer a core set of frameworks and classes for all The iPod touch is primarily a music and video content platform, but it can also run On the iPhone and iPod touch, you develop user interfaces using the UIKit​  Handling UIKit Gestures. Use gesture recognizers to simplify touch handling and create a consistent user experience. Coordinating Multiple Gesture Recognizers.

Not a direct answer to the question, but a very common cause of vanishing touches is for a control to be in a uiview which has a smaller size than that control, but is not clipping its bounds, so you won't see that the parent view is smaller (or even possibly zero-sized).

Parent UIView size=0x0, clipToBounds=false

   Child UIButton size=100x50

=> Child Button won't get any touch events.

Cocoa, into the StackView. The ScrollView scrolls fine, but I cant get any touches to register on the arranged subviews. I would like to have a UIButton but for debug purposes I have tried using both touchesBegan and Have you made the UIView. Want to try for yourself? Check out my UIKitDebugging repository and add all files to your repository. Remember, that’s just for debugging and to satisfy your curiosity, don’t ship any of that. Here’s some interesting output. The touch and gesture logging seems very useful.

You can use the new Xcode6 live view debugging and by turning the view hierarchy in 3D you can see which views are above the ones you care for and inspect them.

Touches not passed to UIStackView arranged subviews : swift, The debugging tools you find in Xcode will help you find the root cause of a Sign up for my iOS development course, and learn how to build great iOS 13 It's like how a caterpillar would eat through a cake with different levels. You can​'t inspect the source code of UIKit frameworks, so when you try to go  30 How to debug who is eating my touches in UIKit? Sep 29 '14. 27 [__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance Aug 12 '14.

My full Swift Example following @Bryan Chen and @kelin Answer ...

import UIKit

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow? = TestWindow()
    // ....


class TestWindow:UIWindow {
    override func sendEvent(_ event: UIEvent) {


        //<UITouchesEvent: 0x6000008b1f80> timestamp: 366545 touches: {(
        //    <UITouch: 0x7fa056d37dc0> phase: Ended tap count: 1 force: 0.000 
        //window: <zollundpost.TestWindow: 0x7fa056c020a0; baseClass = UIWindow; 
        //frame = (0 0; 375 812); gestureRecognizers = <NSArray: 0x6000034f9530>; 
        //layer = <UIWindowLayer: 0x600003abd940>> view: <UITableViewCellContentView: 
        //0x7fa059a55090; frame = (0 0; 375 72); opaque = NO; gestureRecognizers = 
        //<NSArray: 0x6000034293e0>; layer = <CALayer: 0x600003ac8320>> location in 
        //window: {165, 358.33332824707031} previous location in window: 
        //{144.33332824707031, 358.66665649414062} location in view: {165, 
        //44.999992370605469} previous location in view: {144.33332824707031, 
        //    )}


Get Started with Debugging in Xcode – LearnAppMaking, But once they're on the screen, each pixel consists of three color This may seem trivial, but for large textures this can be very time-consuming. blended layers is all about (which is also available in the Simulator's Debug menu). UIKit maintains a stack of contexts and the UIKit methods always draw into the top context. However, if you use custom views to display your content, you must handle all touch events that occur in your views. There are two ways to handle touch events yourself. Use gesture recognizers to track the touches; see Handling UIKit Gestures. Track the touches directly in your UIView subclass; see Handling Touches in Your View.

Getting Pixels onto the Screen ·, fespinoza/DevNotes. source: ios - How to debug who is eating my touches in UIKit? - Stack Overflow. <img width=“468” alt=“Screenshot 2019-07-30 at 13 23 58”  A touch object also contains a timestamp indicating when the touch occurred, an integer representing the number of times the user tapped the screen, and the phase of the touch in the form of a constant that describes whether the touch began, moved, or ended, or whether the system canceled the touch.

UIKit, Bluetooth; Camera; Force Touch; iBeacon; Location; Other Hardware News, Blogs and more; UIKit references; Forums and discuss lists; Tutorials and Keynotes iOS 13 & Swift 5 - The Complete iOS App Development Bootcamp Netfox - A lightweight, one line setup, iOS / macOS network debugging library! The UIKit framework provides the required infrastructure for your iOS or tvOS apps. It provides the window and view architecture for implementing your interface, the event handling infrastructure for delivering Multi-Touch and other types of input to your app, and the main run loop needed to manage interactions among the user, the system, and your app.

Awesome iOS, Show/Hide Debug – allows you to hide or show the debug or console area: the place these components from scratch, creating an app would be time-​consuming. Although this somewhat strays from Swift programming, we will see how UIKit but also things like classes for animation, touches, gestures, drag and drop. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

  • The zero-size view bit me. I had made some intermediate views to keep z-order sane, but I forgot to update the frames of the intermediate views, so they stayed at zero size. Once I updated them in LayoutSubviews taps started flowing again.
  • I was just bitten by this too. In summary, check two things in the hierarchy of the view which has this problem (assuming it's not covered by a non-interactive transparent view) : is userInteractionEnabled == true, and if height and width are > 0.
  • what value should we set for the first parameter of hitTest? @Bryan
  • A CGPoint, which can be read from the event. you need to check if it is a touch event first
  • If anyone would need to implement it, due to the fact it uses private API, here's the full code for it in objc: - (void)sendEvent:(UIEvent *)event { UITouch *touch = [event.allTouches anyObject]; UIView *view = [self hitTest:[touch locationInView:touch.view] withEvent:event]; NSLog(@"Touch captured: %@", [view valueForKey:@"recursiveDescription"]); [super sendEvent:event]; }
  • This absolutely saved my bacon.
  • @Nestor I'm glad it helped