<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIView/hitTest(_:with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIView(im)hitTest:withEvent:"
  },
  "title" : "hitTest(_:with:)"
}
-->

# hitTest(_:with:)

Returns the farthest descendant in the view hierarchy of the current view, including itself, that contains the specified point.

```
func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?
```

## Parameters

`point`

A point in the view’s local coordinate system.

`event`

The event that warrants a call to this method. If you’re calling this method from outside your event-handling code, you can specify `nil`.

## Return Value

The view object that’s the farthest descendent of the current view and contains `point`. Returns `nil` if the point lies completely outside the view hierarchy of the current view.

## Discussion

This method traverses the view hierarchy by calling the [`point(inside:with:)`](/documentation/UIKit/UIView/point(inside:with:)) method of each subview to determine which subview to send a touch event to. If [`point(inside:with:)`](/documentation/UIKit/UIView/point(inside:with:)) returns <doc://com.apple.documentation/documentation/Swift/true>, this method continues to traverse the subview hierarchy until it finds the frontmost view that contains the specified point. If a view doesn’t contain the point, this method ignores its branch of the view hierarchy. You rarely need to call this method yourself, but you might override it to hide touch events from subviews.

This method ignores view objects that are hidden, that have disabled user interactions, or that have an alpha level less than `0.01`. This method doesn’t take the view’s content into account when determining a hit, so it can return a view even if the specified point is in a transparent portion of that view’s content.

This method doesn’t report points that lie outside the view’s bounds as hits, even if they actually lie within one of the view’s subviews. This situation can occur if the view’s [`clipsToBounds`](/documentation/UIKit/UIView/clipsToBounds) property is <doc://com.apple.documentation/documentation/Swift/false> and the affected subview extends beyond the view’s bounds.

> Note:
> When the system calls this method to perform hit-testing for event routing, it expects the resulting view to be part of a ``doc://com.apple.uikit/documentation/UIKit/UIWindow`` hierarchy.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)