Hi,
I'm trying to toggle the visibility of an overlay by using hovering. However, I found onHover()
and onContinuousHover()
don't work on visionOS. Is it intended?
Is there an solution for my case?
Hi,
I'm trying to toggle the visibility of an overlay by using hovering. However, I found onHover()
and onContinuousHover()
don't work on visionOS. Is it intended?
Is there an solution for my case?
Hi @huanxiangwang , take a look at this video on "Enhance your iPad and iPhone apps for the Shared Space" from WWDC23, especially the Interaction part starting at 1 minute. This should help answer your question.
Hi @sha921 , thanks for your input. However, I'm building a native visionOS app from ground up. I'm pretty sure onHover()
and onContinuousHover()
don't work on native visionOS apps. I'm not sure if it's a bug or delibarately done so for privacy reasons as I heard from multiple WWDC23 sessions that where user is looking at is detected at the system level not the app level.
There is also no way to extend the HoverEffect
to create my own.
Basically what I would like to achive is to display an overlay above an image when the user is looking at it, and I found it's impossible. Below is an abstract code snippet.
struct ImageView: View {
@State private var isHovering = false
var body: some View {
someImage
.onHover(perform: { hover in
isHovering = hover
})
.overlay(alignment: .bottom, content: {
if isHovering {
imageInfo
}
})
}
}
Hey @sha921, I'm also trying to develop on visionOS, and I've noticed the same thing. I believe it might be tied to privacy constraints. It's odd that there isn't a clear way to implement onHover behaviors for native apps, especially when it seems like a fundamental feature. Have you come across any workarounds or alternatives to achieve similar interactivity? I'd appreciate any pointers! here you can get more help https://developer.apple.com/support/
Yeah, it would be cool to show controls based on hover state.
Hi all, the only way to use hover effects in visionOS with SwiftUI is to do something like this:
var body: some View {
Rectangle()
.contentShape(.hoverEffect, RoundedRectangle(cornerRadius: 10))
.hoverEffect()
}
This would put a RoundedRectangle hover effect on top of the Rectangle, of course this can be customized however you want. There are also three options (automatic, highlight, and lift) that you can apply like .hoverEffect(.lift)
, etc
Due to privacy, there are no custom hover effects like changing color, expanding controls, showing overlays, etc
Hope it's added in the future as it seems like a fundamental feature that users would expect. Otherwise we need to show too much information on the screen, or require taps that could be accomplished by just glancing at an entity.
.onHover should work for visionPro, I don't understand why is disabled, can some one from apple confirm that this function is not going to be included in the final release ?
It works in the Simulator only with this tool (choose and click on your window):
Same here. I'm wanting to do a cursor for drawing the way the Vision version of the Freehand app does, but it looks like that isn't possible at this time?