Take a look at this simple code:
import Cocoa
import SwiftUI
struct DemoView: View {
var body: some View {
Text("Click me!")
.onTapGesture {
print("Clicked")
}
}
}
class FlippedView: NSView {
override var isFlipped: Bool {
return true
}
}
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let stackView = NSStackView()
stackView.orientation = .vertical
stackView.alignment = .leading
stackView.spacing = 0
stackView.translatesAutoresizingMaskIntoConstraints = false
let hostView = NSHostingView(rootView: DemoView())
stackView.addArrangedSubview(hostView)
let scrollView = NSScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
let flippedView = FlippedView()
flippedView.addSubview(stackView)
scrollView.documentView = flippedView
view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: view.topAnchor),
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
}
}
I need my scroll view to start at the very top, so i put it inside a flipped document view.
But now .onTapGesture does not fire.
Kopyl
Users receive reputation points by contributing quality content to the forums.
Posts include post and replies published on the forums.
Post authors can mark replies as Accepted to indicate successful solutions.
Apple Developer Forums admins can mark replies as Apple Recommended to indicate an approved solution
Last seen
User for
From
Kyiv, Ukraine
- Designer
- Developer
- Executive
- Hobbyist
- iOS
- macOS
- Web
- Books
- Business
- Developer Tools
- Education
- Entertainment
- Finance
- Food & Drink
- Games
- Graphics & Design
- Health & Fitness
- Kids
- Lifestyle
- Magazines & Newspapers
- Medical
- Music
- Navigation
- News
- Photo & Video
- Productivity
- Reference
- Safari Extensions
- Shopping
- Social Networking
- Sports
- Travel
- Utilities
- Weather
- Accessibility & Inclusion
- Apple Intelligence & Machine Learning
- App Services
- App Store, Distribution & Marketing
- Audio & Video
- Business & Education
- Design
- Developer Tools
- Graphics & Games
- Health & Fitness
- Maps & Location
- Photos & Camera
- Privacy & Security
- Safari & Web
- Spatial Computing
- Swift
- SwiftUI & UI Frameworks
- System Services
- English