ios – SwiftUI HStack clipping subviews


I am trying to implement a video scrubber/trimmer in SwiftUI. To do this, put image thumbnails in an HStack as follows:

struct ThumbnailsView: View {
  @State private var thumbImages:[ThumbImage] = []

   var body: some View {
       ForEach(thumbImages, id: \.time) { thumbImage in
           Image(uiImage: thumbImage.image)
              .border(Color.white, width: 5)
       }
       .padding(5)
    }
 }

 struct ThumbImage {
   var time: CMTime
   let image: UIImage
 }

This should basically allow to construct series of images in the scrubber/trimmer (like in Photos app). However, my requirement (which is different from behavior in Photos app) is that as user trims from either end, the trimmer gets shortened and clips the leftmost(or rightmost depending on direction of trim) thumbnail by respective amount, so that only a fraction of the leftmost or rightmost thumbnail is shown as the user drags the end of the trimmer. I could do it in UIKit but just want to understand how this can be done in SwiftUI.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img