ScrollView +自定义视图+ ContextMenu动画故障-SwiftUI

时间:2020-10-19 14:20:59

标签: swift animation swiftui scrollview

是否有解决方法来修复这些动画故障? Glitch video

  1. 滚动动画出现故障
  2. 视图消失不到一秒钟的那个

视图语义为:

TabView {
   NavigationView {
      ScrollView {
       VStack {
          ForEach(){
             MyCustomView()
                .contextMenu()

MyCustomView在下面,如果有人想对其进行测试:

struct CardVew: View {
    var title: String
    var description: String
    var name: String
    var task: String
    var done: Bool
    
    let tapVibration = UIImpactFeedbackGenerator(style: .light)
    @State var details = false
    
    var body: some View {
        ZStack(alignment: .leading) {
            RoundedRectangle(cornerRadius: 15)
                .foregroundColor(Color("cardGray"))
                .opacity(0.24)
            VStack(alignment: .leading, spacing: .zero) {
                titleBlock
                
                descriptionBlock
                
                bottomBlock
            }
            .padding([.leading, .trailing], 20)
            .padding(.bottom, 15)
            .padding(.top, 24)
            
        }
        .padding([.leading, .trailing], 12)
        .sheet(isPresented: $details) {
            CardSheetView(
                title: title,
                description: description,
                task: task,
                name: name
            )
        }
        .onTapGesture {
            tapVibration.impactOccurred()
            details = true
        }
        .onAppear {
            tapVibration.prepare()
        }
    }
    
    private var titleBlock: some View {
        HStack(alignment: .top) {
            Text(title)
                .font(.system(size: 22, weight: .bold))
                .fixedSize(horizontal: false, vertical: true)
                .frame(width: 244, alignment: .leading)
                .padding(.bottom, 4)
            if done {
                Spacer()
                Image("done")
                    .opacity(0.8)
            }
        }
    }
    
    private var bottomBlock: some View {
        HStack(alignment: .bottom) {
            HStack(alignment: .center) {
                Image(systemName: "calendar")
                Text("22.09")
            }
            Spacer()
            Text(name)
                .multilineTextAlignment(.trailing)
                .opacity(0.6)
                .font(.footnote)
                .frame(width: 211, alignment: .trailing)
        }
    }
    
    private var descriptionBlock: some View {
        Text(description)
            .opacity(0.8)
            .fixedSize(horizontal: false, vertical: true)
            .frame(width: 247, alignment: .leading)
            .padding(.bottom, 38)
    }
}

我试图排除所有动画,图纸和任何可能导致这种行为的东西,但没有成功

0 个答案:

没有答案