# How can I slide the Slider under a View in SwiftUI?

**URL:** <https://forums.kodeco.com/t/how-can-i-slide-the-slider-under-a-view-in-swiftui/119282>\
**Category:** SwiftUI by Tutorials\
**Created:** [September 5, 2020, 6:13am UTC](https://forums.kodeco.com/t/how-can-i-slide-the-slider-under-a-view-in-swiftui/119282 "2020-09-05T06:13:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hopy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hopy/32/102075_2.png) [@hopy](https://forums.kodeco.com/u/hopy)\
**Post date:** [September 5, 2020, 6:13am UTC](https://forums.kodeco.com/t/how-can-i-slide-the-slider-under-a-view-in-swiftui/119282/1 "2020-09-05T06:13:27Z")

</div>

There are two views (Slider and Button) under a view (Rectangle):

```auto
struct ContentView: View {
    //@State var val = false
    @State var floatVal = 0.0
    
    var body: some View {
        ZStack {
            VStack {
                Text("Control penetration")
                    .font(.title)
                
                //Slider can't slide
                Slider(value: $floatVal, in: 0...100)
                
                //Toggle can't toggle too
                //Toggle(isOn: $val){EmptyView()}
                
                //only button can tap
                Button(action: {
                    print("Tapped!")
                }){
                    Text("Can you tap me???")
                }
                
            }
            .padding()
            
            Rectangle()
                .fill(Color.green.opacity(0.2))
                .allowsHitTesting(false)
        }
    }
}

```

I use allowsHitTesting() to make the click penetrate to the bottom.

But only the Button can respond to click, the Slider can not slide!

What’s wrong with it? How can I make the Slider respond slide too? thanks a lot!

---

<div class="post-metadata">

**Author:** ![audrey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/audrey/32/111607_2.png) [@audrey](https://forums.kodeco.com/u/audrey)\
**Post date:** [September 6, 2020, 4:15am UTC](https://forums.kodeco.com/t/how-can-i-slide-the-slider-under-a-view-in-swiftui/119282/2 "2020-09-06T04:15:17Z")

</div>

hi Hopy! I guess the main reason is because you don’t tap a slider. A SO answer says you can’t scroll a scrollview through a top layer either.

Until SwiftUI gets its own version of `userInteractionEnabled`, you might try creating a `UIViewRepresentable` version of the rectangle

---

<div class="post-metadata">

**Author:** ![hopy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hopy/32/102075_2.png) [@hopy](https://forums.kodeco.com/u/hopy)\
**Post date:** [September 6, 2020, 8:50am UTC](https://forums.kodeco.com/t/how-can-i-slide-the-slider-under-a-view-in-swiftui/119282/3 "2020-09-06T08:50:36Z")

</div>

hi，谢谢您的回答。

其实我是想在Slider上覆盖一个有圆形空洞(用Path eofFill组合1个矩形和1个圆形)的View，然后只有空洞中的Slider可以操作，其它部分的控件不可以响应用户的操作。

如果用userInteractionEnabled，那么所有控件都可以响应用户操作了，这不符合我的要求。

求教，谢谢。

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 9, 2021, 7:31pm UTC](https://forums.kodeco.com/t/how-can-i-slide-the-slider-under-a-view-in-swiftui/119282/4 "2021-04-09T19:31:42Z")

</div>

@hopy Please post your comments in English in order to get answers. Thank you!
