Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    AWS expands Anthropic partnership with Claude Platform launch

    May 12, 2026

    automator – Convert HEIC to JPG retaining EXIF

    May 12, 2026

    What Is Single Sign-On (SSO)? Benefits, Security & How It Works

    May 12, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – How do I get a blending mode to apply to my ScrollView while not affecting the background on latest SwiftUI?
    iOS Development

    ios – How do I get a blending mode to apply to my ScrollView while not affecting the background on latest SwiftUI?

    big tee tech hubBy big tee tech hubSeptember 25, 2025002 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – How do I get a blending mode to apply to my ScrollView while not affecting the background on latest SwiftUI?
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    The masking approach could work for scroll views too, if you track the frames of each subview of the scroll view. You could use a struct like this:

    struct ScrollContentFrame: Identifiable {
        let id: AnyHashable
        let frame: Anchor
        let shape: AnyShape
    }
    

    I’m keeping things very general here by using AnyHashable and AnyShape. If this is just a one-off effect you want to do, I would recommend using an appropriate ID type, and if the shape is known and constant, remove shape.

    Next, write a preference key that collects an array of these,

    struct ScrollContentFramesKey: PreferenceKey {
        static var defaultValue: [ScrollContentFrame] { [] }
        
        static func reduce(value: inout [ScrollContentFrame], nextValue: () -> [ScrollContentFrame]) {
            value.append(contentsOf: nextValue())
        }
    }
    

    Set the preference key using an anchorPreference,

    .anchorPreference(key: ScrollContentFramesKey.self, value: .bounds) { anchor in
        [
            ScrollContentFrame(
                id: i,
                frame: anchor,
                shape: AnyShape(RoundedRectangle(cornerRadius: 16))
            )
        ]
    }
    

    The color-blended linear gradient can be added as an overlayPreferenceValue instead of ZStack.

    .overlayPreferenceValue(ScrollContentFramesKey.self) { scrollContentFrames in
        LinearGradient(
            colors: [.blue, .orange],
            startPoint: .topLeading,
            endPoint: .bottomTrailing
        )
        .allowsHitTesting(false)
        .mask {
            GeometryReader { proxy in
                ForEach(scrollContentFrames) { content in
                    let frame = proxy[content.frame]
                    content.shape
                        .frame(width: frame.width, height: frame.height)
                        .position(x: frame.midX, y: frame.midY)
                }
            }
        }
        .blendMode(.color)
        .ignoresSafeArea()
    }
    

    Full code for the view:

    struct ContentView: View {
        var body: some View {
            ZStack {
                LinearGradient(
                    colors: [.purple, .pink],
                    startPoint: .top,
                    endPoint: .bottom
                )
                .ignoresSafeArea()
                ScrollView {
                    LazyVStack(spacing: 20) {
                        ForEach(0..<10) { i in
                            RoundedRectangle(cornerRadius: 16)
                                .fill(.white)
                                .frame(height: 120)
                                .overlay(
                                    Text("Card \(i)")
                                        .font(.headline)
                                        .foregroundColor(.red)
                                )
                                .anchorPreference(key: ScrollContentFramesKey.self, value: .bounds) { anchor in
                                    [
                                        ScrollContentFrame(
                                            id: i,
                                            frame: anchor,
                                            shape: AnyShape(RoundedRectangle(cornerRadius: 16))
                                        )
                                    ]
                                }
                                .padding(.horizontal)
                        }
                    }
                    .padding(.vertical, 50)
                }
                .background(Color.clear)
                .overlayPreferenceValue(ScrollContentFramesKey.self) { scrollContentFrames in
                    LinearGradient(
                        colors: [.blue, .orange],
                        startPoint: .topLeading,
                        endPoint: .bottomTrailing
                    )
                    .allowsHitTesting(false)
                    .mask {
                        GeometryReader { proxy in
                            ForEach(scrollContentFrames) { content in
                                let frame = proxy[content.frame]
                                content.shape
                                    .frame(width: frame.width, height: frame.height)
                                    .position(x: frame.midX, y: frame.midY)
                            }
                        }
                    }
                    .blendMode(.color)
                    .ignoresSafeArea()
                }
            }
        }
    }
    



    Source link

    affecting Apply background blending iOS Latest mode ScrollView SwiftUI
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    ios – How to add shadow to border?

    May 12, 2026

    My Outer Loop | Cocoanetics

    May 11, 2026

    javascript – Will my Capacitor WebView social media app (offline, haptics, push notifs, camera, 4 languages) be rejected under Guideline 4.2.2?

    May 10, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    AWS expands Anthropic partnership with Claude Platform launch

    May 12, 2026

    automator – Convert HEIC to JPG retaining EXIF

    May 12, 2026

    What Is Single Sign-On (SSO)? Benefits, Security & How It Works

    May 12, 2026

    Vespa AI and Surpassing the Limits of Vector Search

    May 12, 2026
    Timer Code
    15 Second Timer for Articles
    20
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    AWS expands Anthropic partnership with Claude Platform launch

    May 12, 2026

    automator – Convert HEIC to JPG retaining EXIF

    May 12, 2026

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2026 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.