If you’re developing or modifying an iPad app running on Mac (via Catalyst or Apple Silicon support) and want to hide the cursor, you can use the following Swift code to achieve this.
Method 1: Hide Cursor in a UIView or Entire App
Use NSCursor.hide() to hide the cursor when the app is running on macOS.
#if targetEnvironment(macCatalyst)
import AppKit // Required for macOS cursor control
class MyView: UIView {
override func didMoveToWindow() {
super.didMoveToWindow()
NSCursor.hide() // Hide the cursor
}
}
#endif
How it works:
• #if targetEnvironment(macCatalyst) ensures this runs only on macOS , not iPad.
• NSCursor.hide() hides the cursor when the view is shown.
• You can call NSCursor.unhide() later if you need to restore it.
Method 2: Hide Cursor in a macOS-Only Scene (For Catalyst Apps)
If you are using UIResponder-based event handling, you can override cursorUpdate(with:):
#if targetEnvironment(macCatalyst)
import UIKit
import AppKit
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Hide the cursor when the view appears
NSCursor.hide()
}
override func cursorUpdate(with event: NSEvent) {
NSCursor.hide()
}
}
#endif
Method 3: Hide Cursor Only When Touching (For Drawing or Media Apps)
If your app supports Apple Pencil or touch input , you may want to hide the cursor only when touching :
#if targetEnvironment(macCatalyst)
import UIKit
import AppKit
class MyView: UIView {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
NSCursor.hide()
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
NSCursor.unhide()
}
}
#endif
Use Case:
• Useful for drawing apps (e.g., Procreate, Affinity Designer) or media apps.
Bonus: Prevent Cursor from Appearing in a Full-Screen View
If your app has a full-screen mode , you can force the cursor to stay hidden :
#if targetEnvironment(macCatalyst)
import UIKit
import AppKit
class MyFullScreenViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NSCursor.hide()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NSCursor.unhide()
}
}
#endif
When to Use These Methods
Use Case |
Recommended Method |
Hide cursor app-wide |
Method 1 (NSCursor.hide()) |
Hide cursor only in a specific view/controller |
Method 2 (override cursorUpdate) |
Hide cursor when using touch/Apple Pencil |
Method 3 (touchesBegan) |
Hide cursor in full-screen mode |
Method 4 (viewDidAppear) |