Hi,
I am having trouble changing from deprecated NavigationView to NavigationStack.
I have looked through the article, and a number of examples and tutorials - they all show examples where the user clicks on a choice or a button in the view. But in my case, the navigation is programmatic based on changes to a value. I have below the old code, and my attempt at new revised code ( needs to run on IOS16, and cannot use API introduced in IOS 17). The new code compiles fine, but the screen does not navigate to new views as the value changes. I debug print the value as it changes, and the value for 'detailView' does change. The old code works without a problem - just that I get a warning that I am using deprecated APIs.
The old code:
struct MainView: View {
@EnvironmentObject var gameVm: GameViewModel
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: PlayView().transition(.slide),
tag: .playView, selection: $gameVm.detailView) {
EmptyView()
}
NavigationLink(destination: GamePausedView().transition(.scale),
tag: .gamePausedView, selection: $gameVm.detailView) {
EmptyView()
}
NavigationLink(destination: SettingsView().transition(.slide),
tag: .settingsView, selection: $gameVm.detailView) {
EmptyView()
}
IdleView().transition(.slide)
}
}
.navigationViewStyle(.stack)
}
}
My attempt at the revised code:
struct GameMainView: View {
@EnvironmentObject var gameVm: GameViewModel
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
VStack {
NavigationLink(value: DetailView.playView) {
EmptyView()
}
NavigationLink(value: DetailView.gamePausedView) {
EmptyView()
}
NavigationLink(value: DetailView.settingsView) {
EmptyView()
}
IdleView().transition(.slide)
}
}
.navigationDestination(for: DetailView.self) { dtlViewType in
if dtlViewType == .playView {
PlayView().transition(.slide)
} else if dtlViewType == .settingsView {
SettingsView().transition(.slide)
} else if dtlViewType == .gamePausedView {
GamePausedView().transition(.slide)
}
}
}
}
What am I doing wrong? Thanks in advance for any help.
Post
Replies
Boosts
Views
Activity
I need to associate sound with the movement of a sprite. Movement can be as a result of physics, not as a result of an SKAction. When the object is sliding thee should be sliding sound throughout the time when it is sliding, and then a different sound when it bumps into a rock and goes up in the air. When the object is airborne, there is no sound, till it falls again - a falling sound, and then slides down with a sliding sound. The sounds associated with the collision ( rock, ground and so on ) are straightforward and work fine. But am having difficulty associating the sound with movement.
The closest result I have is to check the velocity of the sprite's physics body every update cycle and play or stop the sound based on whether the velocity is greater than zero. I tried SKAction.playSoundFileNamed first - the sound kept going even when the object was not moving. I tried adding an SKAudioNode with Play and Stop, with no better result. I finally tried using AVAudioPlayer to play and Pause , which yielded the best results, but the sliding sound still played past the sliding action.
What is the best way to do this?
My code for playing the sound is as follows:
var blockSliding = false
for block in gameBlocks {
if (block.physicsBody?.velocity.dx ?? 0) + (ball.physicsBody?.velocity.dy ?? 0) > 0.05 {
blockSliding = true
break
}
}
if slideSound.isPlaying {
if !blockSliding {
slideSound.pause()
}
} else {
if blockSliding {
slideSound.play()
}
}
I have setup slideSound earlier loading the appropriate sound file into an AVAudioPlayer
I am developing many products and services to help children learn to speak Tamil as a second language.
As part of this platform, I am publishing illustrated children's books that are distributed via Amazon as well as from my website. I am developing a companion reader app for an interactive digital version on the iPad. The books will be narrated on demand, and children will be able to click on words and images to hear Tamil being spoken. I am creating this content for the printed and digital versions. I am writing new stories, and am working with authors/publishers to adapt/translate their existing books for use in this platform.
When the app is first installed, the content for one free book is downloaded for the user, so that there is a book to try the app. Additional books can be purchased individually or as 'packs'.
I apologize if this background seems excessive, but I want to set the stage for my questions.
1. Customers can buy printed and digital books. Can I put in information about how they can buy the printed book in my app?
2. Does all purchasing content have to happen outside the app, or can I have new books(digital version) bought both as in-app purchases and as direct purchases outside the app? This is important, as I want to provide hard copy buyers the ability to get free or discounted access to the digital version - and this can be done when they buy the books from my website. At the same time, I want to provide an easy means for the user to buy content via in-App purchase if they want.