Swiftui: Rotation direction goes reverse as finger moment reaches Bottom of circle

Viewed 102

I am developing a selection dial, and it is working properly which means that the dial is rotating in the same direction as the finger is moving but an issue arises as soon the finger reaches somehow near the bottom portion, the dial start rotating in opposite direction.

enter image description here

VStack {
    Image(icons_list[i].iconNamee)
        .resizable()
        .rotationEffect(Angle(degrees: -180))
        .frame(width: UIScreen.screenWidth / 12, height: UIScreen.screenWidth / 12, alignment: .center)
        .aspectRatio(contentMode: .fit)
        .padding()
        .offset(y:(UIScreen.screenWidth / 3.75))
        .rotationEffect(Angle(degrees: (Double(i) * iconDistanceRatio) ))
        .rotationEffect(Angle(degrees: 180))
}
.rotationEffect(Angle(degrees: Double(totalRotation.width)))

.gesture(
    DragGesture()
        .onChanged { value in
            
            totalRotation.width = value.translation.width +         currentRotation.width
         
            
            if totalRotation.width < 0 {
                let val = Int(abs(totalRotation.width / iconDistanceRatio))
                if val >= (icons_list.count){
                    selectedIndex = 0
                    totalRotation = CGSize.zero
                    
                }else{
                    self.selectedIndex = val
                }
            }
            else{
                let val = (icons_list.count - 1) - Int(abs(totalRotation.width / iconDistanceRatio))
                if Int(abs(totalRotation.width / iconDistanceRatio)) >= (icons_list.count){
                    selectedIndex = 0
                    totalRotation = CGSize.zero
                    
                }else{
                    self.selectedIndex = val
                }
            }
        }
        .onEnded { value in
            currentRotation = totalRotation
            
        }
)
0 Answers
Related