SwiftUI滾動(dòng)方法圖片特效

//
// test4Scroll.swift
// Music
//
// Created by QIAEN on 2025/1/15.
//

import SwiftUI

struct test4Scroll: View {
let safeArea: EdgeInsets
let size: CGSize
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 10) {
ImageView()
VStack(spacing: 10) {
Text("Popular")
.fontWeight(.heavy)
.foregroundStyle(.black)
Text("When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.")
.font(.system(size: 20))
.frame(width: 368, alignment: .leading)
.offset(y: -70)
.padding(15)
}
}
}
}
@ViewBuilder
func ImageView() -> some View {
let height = size.height
GeometryReader{proxy in
let size = proxy.size
let minY = proxy.frame(in: .named("SCROLL")).minY
let progress = minY / (height * (minY > 0 ? 0.5 : 0.8))
Image("avatar4")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: size.width, height: size.height + (minY > 0 ? minY : 0))
.clipped()
.overlay(content: {
ZStack(alignment: .bottom) {
Rectangle()
.fill(.linearGradient(colors: (0...5).map {
Color.black.opacity(Double($0) * 0.2 - progress)
}, startPoint: .top, endPoint: .bottom))
VStack(spacing: 0) {
Text("Chocolate\nCake Recipe")
.font(.system(size: 45))
.fontWeight(.bold)
.multilineTextAlignment(.center)
Text("10K Monthly Viewers")
.font(.caption)
.fontWeight(.bold)
.foregroundStyle(.gray)
.padding(.top, 15)
}
.opacity(1 + (progress > 0 ? -progress : progress))
.padding(.bottom, 55)
.offset(y: minY < 0 ? minY : 0)
}
})
.offset(y: -minY)

    }
    .frame(height: height + safeArea.top)
}

}

Preview {

GeometryReader {
    let safeArea = $0.safeAreaInsets
    let size = $0.size
    test4Scroll(safeArea: safeArea, size: size)
        .ignoresSafeArea(.container, edges: .top)
        .preferredColorScheme(.dark)
}

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市著瓶,隨后出現(xiàn)的幾起案子鞋既,更是在濱河造成了極大的恐慌敢辩,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,744評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異麦射,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)灯谣,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,505評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門潜秋,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人胎许,你說我怎么就攤上這事峻呛。” “怎么了辜窑?”我有些...
    開封第一講書人閱讀 163,105評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵钩述,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我穆碎,道長(zhǎng)切距,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,242評(píng)論 1 292
  • 正文 為了忘掉前任惨远,我火速辦了婚禮谜悟,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘北秽。我一直安慰自己葡幸,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,269評(píng)論 6 389
  • 文/花漫 我一把揭開白布贺氓。 她就那樣靜靜地躺著蔚叨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上蔑水,一...
    開封第一講書人閱讀 51,215評(píng)論 1 299
  • 那天邢锯,我揣著相機(jī)與錄音,去河邊找鬼搀别。 笑死丹擎,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的歇父。 我是一名探鬼主播蒂培,決...
    沈念sama閱讀 40,096評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼榜苫!你這毒婦竟也來了护戳?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,939評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤垂睬,失蹤者是張志新(化名)和其女友劉穎媳荒,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體驹饺,經(jīng)...
    沈念sama閱讀 45,354評(píng)論 1 311
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡肺樟,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,573評(píng)論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了逻淌。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片么伯。...
    茶點(diǎn)故事閱讀 39,745評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖卡儒,靈堂內(nèi)的尸體忽然破棺而出田柔,到底是詐尸還是另有隱情,我是刑警寧澤骨望,帶...
    沈念sama閱讀 35,448評(píng)論 5 344
  • 正文 年R本政府宣布硬爆,位于F島的核電站,受9級(jí)特大地震影響擎鸠,放射性物質(zhì)發(fā)生泄漏缀磕。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,048評(píng)論 3 327
  • 文/蒙蒙 一劣光、第九天 我趴在偏房一處隱蔽的房頂上張望袜蚕。 院中可真熱鬧,春花似錦绢涡、人聲如沸牲剃。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,683評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽凿傅。三九已至缠犀,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間聪舒,已是汗流浹背辨液。 一陣腳步聲響...
    開封第一講書人閱讀 32,838評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留箱残,地道東北人滔迈。 一個(gè)月前我還...
    沈念sama閱讀 47,776評(píng)論 2 369
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像疚宇,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子赏殃,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,652評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 在iOS開發(fā)中敷待,和貨幣價(jià)格計(jì)算相關(guān)的,需要注意計(jì)算精度的問題仁热。即使只是兩位小數(shù)榜揖,也會(huì)出現(xiàn)誤差。使用float類型運(yùn)...
    海邊的遐想閱讀 5,284評(píng)論 0 23
  • 前言 Google Play應(yīng)用市場(chǎng)對(duì)于應(yīng)用的targetSdkVersion有了更為嚴(yán)格的要求抗蠢。從 2018 年...
    申國(guó)駿閱讀 64,080評(píng)論 14 98
  • """1.個(gè)性化消息: 將用戶的姓名存到一個(gè)變量中举哟,并向該用戶顯示一條消息。顯示的消息應(yīng)非常簡(jiǎn)單迅矛,如“Hello ...
    她即我命閱讀 2,888評(píng)論 0 5
  • 我們都是軟弱的人妨猩,所以才會(huì)說謊。我們都是膽小的人秽褒,所以才要武裝壶硅。我們都是一群笨蛋,所以才會(huì)互相傷害销斟。
    所羅門的偽證_dc0a閱讀 2,055評(píng)論 0 3
  • 為了讓我有一個(gè)更快速庐椒、更精彩、更輝煌的成長(zhǎng)蚂踊,我將開始這段刻骨銘心的自我蛻變之旅约谈!從今天開始,我將每天堅(jiān)持閱...
    李薇帆閱讀 1,714評(píng)論 0 2