宜宾建设局网站,热狗seo顾问,学编程去哪里学比较好,慈城旅游网站建设策划书SwiftUI模块系列 - 已更新60篇 SwiftUI项目 - 已更新5个项目 往期Demo源码下载 技术:SwiftUI、SwiftUI4.0、Instagram、Firebase 运行环境: SwiftUI4.0 Xcode14 MacOS12.6 iPhone Simulator iPhone 14 Pro Max SwiftUI基于Firebase搭建一个类似InstagramApp 2/7部分-搭建Tab… SwiftUI模块系列 - 已更新60篇 SwiftUI项目 - 已更新5个项目 往期Demo源码下载 技术:SwiftUI、SwiftUI4.0、Instagram、Firebase 运行环境: SwiftUI4.0 Xcode14 MacOS12.6 iPhone Simulator iPhone 14 Pro Max SwiftUI基于Firebase搭建一个类似InstagramApp 2/7部分-搭建TabBar 概述详细一、运行效果二、项目结构图三、程序实现 - 过程1.创建一个项目命名为 SpotifyResponvieUI1.1.引入资源文件和颜色2. 创建一个虚拟文件New Group 命名为 View3. 创建一个虚拟文件New Group 命名为 Model4. 创建一个文件New File 选择SwiftUI View类型 命名为Album 并且继承Identifiable5. 创建一个文件New File 选择SwiftUI View类型 命名为Home6. 创建一个文件New File 选择SwiftUI View类型 命名为OffsetModifier CodeContentView - 主窗口Home - 主页OffsetModifier - 主要是监听ScrollView的滚动Album - 模型 概述 使用SwiftUI基于Firebase搭建一个类似InstagramApp 2/7部分-搭建TabBar - 效果 详细
一、运行效果 二、项目结构图 三、程序实现 - 过程 思路: 1.创建头部模块 进行测试上下滚动拥有放大缩小效果 2.搭建分类模块 固定在头部下面 3.搭建列表模块 4.监听滚动偏移的操作 1.创建一个项目命名为 SpotifyResponvieUI 1.1.引入资源文件和颜色 颜色 BG #281A1A Green #4DD037 随机图片9张 个人大图背景1张 logo1张 2. 创建一个虚拟文件New Group 命名为 View 3. 创建一个虚拟文件New Group 命名为 Model 4. 创建一个文件New File 选择SwiftUI View类型 命名为Album 并且继承Identifiable 5. 创建一个文件New File 选择SwiftUI View类型 命名为Home 主要是: 6. 创建一个文件New File 选择SwiftUI View类型 命名为OffsetModifier Code
ContentView - 主窗口 主要是展示主窗口Home和设置暗黑模式 import SwiftUIstruct ContentView: View {var body: some View {Home()// 永远是黑暗模式.preferredColorScheme(.dark)}}struct ContentView_Previews: PreviewProvider {static var previews: some View {ContentView()}
}Home - 主页 思路 主要就是展示大图背景 固定的分类 列表模块 //
// Home.swift
// SpotifyResponvieUI (iOS)
//
// Created by lyh on 2022/8/23.
//import SwiftUIstruct Home: View {State var currentType: String Popular// 光滑滑动效果Namespace var animationState var _albums: [Album] albums// x,yState var headerOffsets: (CGFloat,CGFloat) (0,0)var body: some View {ScrollView(.vertical, showsIndicators: false) {VStack(spacing: 0){HeaderView()// 带内容的固定标题LazyVStack(pinnedViews: [.sectionHeaders]) {Section {SongList()} header: {PinnedHeaderView().background(Color.black).offset(y: headerOffsets.1 0 ? 0 : -headerOffsets.1 / 8).modifier(OffsetModifier(offset: $headerOffsets.0, returnFromStart: false)).modifier(OffsetModifier(offset: $headerOffsets.1))}}}}.overlay(content: {Rectangle().fill(.black).frame(height: 50).frame(maxHeight: .infinity,alignment: .top).opacity(headerOffsets.0 5 ? 1 : 0)}).coordinateSpace(name: SCROLL).ignoresSafeArea(.container, edges: .vertical)}// 固定的内容ViewBuilderfunc SongList()-some View{VStack(spacing: 25){ForEach($_albums){$album inHStack(spacing: 12){Text(#\(getIndex(album: album) 1)).fontWeight(.semibold).foregroundColor(.gray)Image(album.albumImage).resizable().aspectRatio(contentMode: .fill).frame(width: 55, height: 55).clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))VStack(alignment: .leading, spacing: 8) {Text(album.albumName).fontWeight(.semibold)Label {Text(65,587,909)} icon: {Image(systemName: beats.headphones).foregroundColor(.white)}.foregroundColor(.gray).font(.caption)}.frame(maxWidth: .infinity,alignment: .leading)Button {album.isLiked.toggle()} label: {Image(systemName: album.isLiked ? suit.heart.fill : suit.heart).font(.title3).foregroundColor(album.isLiked ? Color(Green) : .white)}Button {} label: {Image(systemName: ellipsis).font(.title3).foregroundColor(.white)}}}}.padding().padding(.top,25).padding(.bottom,150)}func getIndex(album: Album)-Int{return _albums.firstIndex { currentAlbum inreturn album.id currentAlbum.id} ?? 0}// 头部视图ViewBuilderfunc HeaderView()-some View{GeometryReader{proxy inlet minY proxy.frame(in: .named(SCROLL)).minYlet size proxy.sizelet height (size.height minY)Image(Ariana).resizable().aspectRatio(contentMode: .fill).frame(width: size.width,height: height 0 ? height : 0,alignment: .top).overlay(content: {ZStack(alignment: .bottom) {// 调暗文本内容LinearGradient(colors: [.clear,.black.opacity(0.8)], startPoint: .top, endPoint: .bottom)VStack(alignment: .leading, spacing: 12) {Text(宇夜iOS).font(.callout).foregroundColor(.gray)HStack(alignment: .bottom, spacing: 10) {Text(Ariana Grande).font(.title.bold())Image(systemName: checkmark.seal.fill).foregroundColor(.blue).background{Circle().fill(.white).padding(3)}}Label {Text(Monthly Listeners).fontWeight(.semibold).foregroundColor(.white.opacity(0.7))} icon: {Text(62,354,659).fontWeight(.semibold)}.font(.caption)}.padding(.horizontal).padding(.bottom,25).frame(maxWidth: .infinity,alignment: .leading)}}).cornerRadius(15).offset(y: -minY)}.frame(height: 250)}// 固定在头部ViewBuilderfunc PinnedHeaderView()-some View{let types: [String] [Popular,Albums,Songs,Fans also like,About]ScrollView(.horizontal, showsIndicators: false) {HStack(spacing: 25){ForEach(types,id: \.self){type inVStack(spacing: 12){Text(type).fontWeight(.semibold).foregroundColor(currentType type ? .white : .gray)ZStack{if currentType type{RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.white).matchedGeometryEffect(id: TAB, in: animation)}else{RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.clear)}}.padding(.horizontal,8).frame(height: 4)}.contentShape(Rectangle()).onTapGesture {withAnimation(.easeInOut){currentType type}}}}.padding(.horizontal).padding(.top,25).padding(.bottom,5)}}
}struct Home_Previews: PreviewProvider {static var previews: some View {ContentView()}
}
OffsetModifier - 主要是监听ScrollView的滚动 用来监听ScrollView的滚动 偏移量的改变 //
// OffsetModifier.swift
// SpotifyResponvieUI (iOS)
//
// Created by lyh on 2022/8/23.
//import SwiftUI// 继承于 ViewModifier 最主要是能方便扩展一些常见的设置属性
/*比如 给Text设置字体\背景颜色\阴影效果extension Text {func songStyle() - some View {self.font(.system(size: 24, weight: .bold)).foregroundColor(.white).shadow(radius: 20)}}⭐️如果是继承ViewModifierstruct SongTextViewModifier: ViewModifier {func body(content: Content) - some View {content.font(.system(size: 24, weight: .bold)).foregroundColor(.white).shadow(radius: 20)}}然后直接通过Text(song).modifier(SongTextViewModifier())设置*/struct OffsetModifier: ViewModifier {Binding var offset: CGFloat// 可选从0返回值var returnFromStart: Bool trueState var startValue: CGFloat 0func body(content: Content) - some View {content.overlay {GeometryReader{proxy inColor.clear.preference(key: OffsetKey.self, value: proxy.frame(in: .named(SCROLL)).minY).onPreferenceChange(OffsetKey.self) { value inif startValue 0{startValue value}print(value);offset (value - (returnFromStart ? startValue : 0))print(offset is \(offset));}}}}
}// 偏好的关键
struct OffsetKey: PreferenceKey{static var defaultValue: CGFloat 0static func reduce(value: inout CGFloat, nextValue: () - CGFloat) {value nextValue()}
}
Album - 模型
//
// Album.swift
// SpotifyResponvieUI (iOS)
//
// Created by lyh on 2022/8/23.
//import SwiftUI// Ablum模型和样本数据
struct Album: Identifiable {var id UUID().uuidStringvar albumName: Stringvar albumImage : Stringvar isLiked : Bool false
}var albums : [Album] [Album(albumName: Positions, albumImage: Album1),Album(albumName: The Best, albumImage: Album2,isLiked: true),Album(albumName: My Everything, albumImage: Album3),Album(albumName: Yours Truly, albumImage: Album4),Album(albumName: Sweetener, albumImage: Album5,isLiked: true),Album(albumName: Rain On Me, albumImage: Album6),Album(albumName: Stuck With U, albumImage: Album7),Album(albumName: 7 rings, albumImage: Album8,isLiked: true),Album(albumName: Bang Bang, albumImage: Album9),] 文章转载自: http://www.morning.bntgy.cn.gov.cn.bntgy.cn http://www.morning.tqjwx.cn.gov.cn.tqjwx.cn http://www.morning.ydnx.cn.gov.cn.ydnx.cn http://www.morning.rqnml.cn.gov.cn.rqnml.cn http://www.morning.pqcbx.cn.gov.cn.pqcbx.cn http://www.morning.fcftj.cn.gov.cn.fcftj.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.zrlms.cn.gov.cn.zrlms.cn http://www.morning.jsxrm.cn.gov.cn.jsxrm.cn http://www.morning.lgmty.cn.gov.cn.lgmty.cn http://www.morning.kxqfz.cn.gov.cn.kxqfz.cn http://www.morning.rnrwq.cn.gov.cn.rnrwq.cn http://www.morning.xmttd.cn.gov.cn.xmttd.cn http://www.morning.cthrb.cn.gov.cn.cthrb.cn http://www.morning.wfjyn.cn.gov.cn.wfjyn.cn http://www.morning.nxdqz.cn.gov.cn.nxdqz.cn http://www.morning.qsy39.cn.gov.cn.qsy39.cn http://www.morning.qymqh.cn.gov.cn.qymqh.cn http://www.morning.gjsjt.cn.gov.cn.gjsjt.cn http://www.morning.knnc.cn.gov.cn.knnc.cn http://www.morning.4q9h.cn.gov.cn.4q9h.cn http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn http://www.morning.monstercide.com.gov.cn.monstercide.com http://www.morning.smj78.cn.gov.cn.smj78.cn http://www.morning.htbgz.cn.gov.cn.htbgz.cn http://www.morning.xnwjt.cn.gov.cn.xnwjt.cn http://www.morning.hjlwt.cn.gov.cn.hjlwt.cn http://www.morning.wnqbf.cn.gov.cn.wnqbf.cn http://www.morning.rqgjr.cn.gov.cn.rqgjr.cn http://www.morning.yrck.cn.gov.cn.yrck.cn http://www.morning.ldfcb.cn.gov.cn.ldfcb.cn http://www.morning.rqmr.cn.gov.cn.rqmr.cn http://www.morning.kngx.cn.gov.cn.kngx.cn http://www.morning.hlrtzcj.cn.gov.cn.hlrtzcj.cn http://www.morning.wjlrw.cn.gov.cn.wjlrw.cn http://www.morning.lwcgh.cn.gov.cn.lwcgh.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.xfncq.cn.gov.cn.xfncq.cn http://www.morning.cwjxg.cn.gov.cn.cwjxg.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.fkffr.cn.gov.cn.fkffr.cn http://www.morning.ngcsh.cn.gov.cn.ngcsh.cn http://www.morning.lokext.com.gov.cn.lokext.com http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.mqfhy.cn.gov.cn.mqfhy.cn http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn http://www.morning.qiyelm.com.gov.cn.qiyelm.com http://www.morning.flxqm.cn.gov.cn.flxqm.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn http://www.morning.trplf.cn.gov.cn.trplf.cn http://www.morning.mjgxl.cn.gov.cn.mjgxl.cn http://www.morning.wmpw.cn.gov.cn.wmpw.cn http://www.morning.fxwkl.cn.gov.cn.fxwkl.cn http://www.morning.rwzqn.cn.gov.cn.rwzqn.cn http://www.morning.yjmns.cn.gov.cn.yjmns.cn http://www.morning.dzgyr.cn.gov.cn.dzgyr.cn http://www.morning.nrqtk.cn.gov.cn.nrqtk.cn http://www.morning.glpxx.cn.gov.cn.glpxx.cn http://www.morning.lrnfn.cn.gov.cn.lrnfn.cn http://www.morning.mlwhd.cn.gov.cn.mlwhd.cn http://www.morning.mjats.com.gov.cn.mjats.com http://www.morning.qsy37.cn.gov.cn.qsy37.cn http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.jjwzk.cn.gov.cn.jjwzk.cn http://www.morning.zxgzp.cn.gov.cn.zxgzp.cn http://www.morning.pwwjs.cn.gov.cn.pwwjs.cn http://www.morning.muzishu.com.gov.cn.muzishu.com http://www.morning.rtbj.cn.gov.cn.rtbj.cn http://www.morning.ffwrq.cn.gov.cn.ffwrq.cn http://www.morning.pdbgm.cn.gov.cn.pdbgm.cn http://www.morning.ngdkn.cn.gov.cn.ngdkn.cn http://www.morning.bpmmq.cn.gov.cn.bpmmq.cn http://www.morning.mpgfk.cn.gov.cn.mpgfk.cn http://www.morning.dgckn.cn.gov.cn.dgckn.cn http://www.morning.hkshy.cn.gov.cn.hkshy.cn http://www.morning.sgbk.cn.gov.cn.sgbk.cn http://www.morning.tjcgl.cn.gov.cn.tjcgl.cn