[英]How to remove animation in SwiftUI NavigationLink when tapping specific views
There is a favorite button in my view which has NavigationLink.在我的视图中有一个收藏按钮,它具有 NavigationLink。 Each time I press the favorite button, opacity animations also shows.
每次我按下最喜欢的按钮时,也会显示不透明动画。 I don't want to show any animation while I tapping the favorite buttons.
我不想在点击收藏按钮时显示任何动画。 I know how to remove animation at whole view, but I hope the animation works when I press outside of favorite buttons.
我知道如何在整个视图中删除动画,但我希望当我按下最喜欢的按钮之外时动画能正常工作。
HStack {
Image(systemName: "a.book.closed.fill")
Text(book.name)
Spacer()
FavoriteButton(isFavorite: $isFavorite)
.onChange(of: isFavorite) { newValue in
book.isFavorite = newValue
model.saveData()
}
}
This is my book row view这是我的书行视图
ScrollView {
ForEach(model.savedBookEntities) { elem in
NavigationLink() {
VocaView(book: elem)
} label: {
BookRow(book: elem)
}
.contextMenu() {
// Some context menus
}
}
}
and this is my ScrollView in NavigationView这是我在 NavigationView 中的 ScrollView
Animation happens on animatable parameter changing.动画发生在可动画参数更改时。 If
FavoriteButton
does not change anything else inside, then try to disable animation for isFavorite
, like如果
FavoriteButton
没有改变内部的任何其他内容,则尝试禁用isFavorite
的动画,例如
HStack {
Image(systemName: "a.book.closed.fill")
Text(book.name)
Spacer()
FavoriteButton(isFavorite: $isFavorite)
.onChange(of: isFavorite) { newValue in
book.isFavorite = newValue
model.saveData()
}
.animation(nil, value: isFavorite) // << here !!
}
//.animation(nil, value: isFavorite) // << or here !!
also book.isFavorite
might affect, so if above would not work for you try the same with book.isFavorite
. book.isFavorite
也可能会影响,因此如果上述方法对您不起作用,请尝试使用book.isFavorite
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.