<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIHoverGestureRecognizer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIHoverGestureRecognizer"
  },
  "title" : "UIHoverGestureRecognizer"
}
-->

# UIHoverGestureRecognizer

A continuous gesture recognizer that interprets pointer movement over a view.

```
class UIHoverGestureRecognizer
```

## Overview

On macOS and iPadOS devices, a person can move the pointer over user interface elements. For some UI designs, it’s important to know when the pointer moves over an element, with no other user interactions, such as clicking the mouse button. The text for a hyperlink, for instance, may change colors or appear with an underline as the pointer moves over the link. This creates a rollover effect.

> Note:
> On iOS, this class doesn’t recognize gestures.

To provide this experience in your app, add a hover gesture recognizer that reacts as the pointer moves over the view. Provide the gesture recognizer with a `target` and `action` that the system calls when the pointer enters, exits, and moves across the view. [`UIHoverGestureRecognizer`](/documentation/UIKit/UIHoverGestureRecognizer) has no effect when your app runs in iOS. The following code changes the button’s default color to red as the pointer moves over the button.

```swift
class ViewController: UIViewController {

    @IBOutlet var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        let hover = UIHoverGestureRecognizer(target: self, action: #selector(hovering(_:)))
        button.addGestureRecognizer(hover)
    }

    @objc
    func hovering(_ recognizer: UIHoverGestureRecognizer) {
        switch recognizer.state {
        case .began, .changed:
            button.titleLabel?.textColor = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1)
        case .ended:
            button.titleLabel?.textColor = UIColor.link
        default:
            break
        }
    }
}
```

## Topics

### Supporting Apple Pencil hover

[`altitudeAngle`](/documentation/UIKit/UIHoverGestureRecognizer/altitudeAngle)

A value that represents the altitude angle of the hovering pointing device.

[`azimuthAngle(in:)`](/documentation/UIKit/UIHoverGestureRecognizer/azimuthAngle(in:))

A value that represents the azimuth angle of the hovering pointing device in the specified view.

[`azimuthUnitVector(in:)`](/documentation/UIKit/UIHoverGestureRecognizer/azimuthUnitVector(in:))

A value that represents the azimuth unit vector of the hovering pointing device in the specified view.

[`rollAngle`](/documentation/UIKit/UIHoverGestureRecognizer/rollAngle)

A value that represents the current barrel-roll angle of Apple Pencil.

[`zOffset`](/documentation/UIKit/UIHoverGestureRecognizer/zOffset)

A value that represents the normalized distance between the screen and a hovering pointing device, such as Apple Pencil.



---

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)