昨天,我安装了cocoapods和我正在为一个学校项目做的音乐播放器应用程序的防火墙依赖项。我总是创建新的分支来尝试它,以防它不起作用。我使用的是最新版本的Xcode和最新版本的firebase与。
我的ContentView中有几个结构,例如SongCell、唱片、歌曲和AlbumArt。
然后,我有了另一个名为PlayerView的快速文件,在这里,我为播放歌曲的播放器设计了视图。在这里,我有一个V堆栈,其中显示文本和AlbumArt。所有这些都没有任何问题,直到我安装了podfile,并将应用程序连接到了firebase。然后,突然之间,我无法构建或运行应用程序,因为'AlbumArt在PlayerView文件中的作用域中找不到‘。
摘要:
中有一个名为AlbumArt的结构
AlbumArt(相册:相册,isWithText:假)
中“无法在范围内找到AlbumArt”
提前谢谢。我将发布来自ContentView、PlayerView和下面的podfile的代码。
ContentView中的代码:
import SwiftUI
import Firebase
struct Album : Hashable {
var id = UUID()
var name : String
var image : String
var songs : [Song]
}
struct Song : Hashable {
var id = UUID()
var name : String
var time : String
}
struct ContentView: View {
@ObservedObject var data : MyData
@State private var currentAlbum : Album?
var body: some View {
NavigationView{
ScrollView{
ScrollView(.horizontal, showsIndicators: false, content: {
LazyHStack{
ForEach(self.data.albums, id:\.self, content: {
album in
AlbumArt(album: album, isWithText: true).onTapGesture {
self.currentAlbum = album
}
})
}
})
LazyVStack{
if self.data.albums.first == nil {
EmptyView()
}else {
ForEach((self.currentAlbum?.songs ?? self.data.albums.first?.songs) ??
[Song(name:"Song 1", time: "3:11"),
Song(name:"Song 2", time: "3:11"),
Song(name:"Song 3", time: "3:11"),
Song(name:"Song 4", time: "3:11"),
Song(name:"Song 5", time: "3:11"),
Song(name:"Song 6", time: "3:11")],
id: \.self,
content: {
song in
SongCell(album: currentAlbum ?? self.data.albums.first!, song: song)
})
}
}.navigationTitle("Sinemark")
}
}
}
struct AlbumArt : View{
var album : Album
var isWithText : Bool
var body: some View {
ZStack (alignment: .bottom, content: {
Image(album.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 170, height: 200, alignment: .center)
if isWithText == true {
ZStack {
Blur(style: .dark)
Text(album.name).foregroundColor(.white)
}.frame(height: 60, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}
}).frame(width: 170, height: 200,alignment: .center) .clipped().cornerRadius(20).shadow(radius: 10).padding(20)
}
}
struct SongCell : View{
var album : Album
var song : Song
var body: some View{
NavigationLink(
destination: PlayerView(album: album, song: song), label: {
HStack{
ZStack{
Circle().frame(width: 50, height: 50, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
Circle().frame(width: 20, height: 20, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).foregroundColor(.white)
}
Text(song.name).bold()
Spacer()
Text(song.time)
}.padding(20)
}).buttonStyle(PlainButtonStyle())
}
}
}PlayerView中的代码:
import Foundation
import SwiftUI
struct PlayerView : View {
var album : Album
var song : Song
@State var isPlaying : Bool = false
var body: some View {
ZStack {
Image(album.image).resizable().edgesIgnoringSafeArea(.all)
Blur(style: .dark).edgesIgnoringSafeArea(.all)
VStack{
Spacer()
AlbumArt(album: album, isWithText: false)
Text(song.name).font(.title).fontWeight(.light).foregroundColor(.white)
Spacer()
ZStack {
Color.white.cornerRadius(20).shadow(radius: 10)
HStack {
Button(action: self.previous, label: {
Image(systemName: "arrow.left.circle").resizable()
}).frame(width: 50, height: 50, alignment: .center).foregroundColor(Color.black.opacity(0.2))
Button(action: self.playPause, label: {
Image(systemName: isPlaying ? "pause.circle.fill" : "play.circle.fill").resizable()
}).frame(width: 70, height: 70, alignment: .center).padding()
Button(action: self.next, label: {
Image(systemName: "arrow.right.circle").resizable()
}).frame(width: 50, height: 50, alignment: .center).foregroundColor(Color.black.opacity(0.2))
}
}.padding().edgesIgnoringSafeArea(.bottom).frame(height: 200, alignment: .center)
}
}
}
func playPause() {
self.isPlaying.toggle()
}
func next () {
}
func previous () {
}
}我的文件:
# Uncomment the next line to define a global platform for your project
platform :ios, '14.4'
target 'BandApp_MusicPlayer' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for BandApp_MusicPlayer
pod 'Firebase/Firestore'
pod 'Firebase/Storage'
pod 'Firebase/Analytics'
target 'BandApp_MusicPlayerTests' do
inherit! :search_paths
# Pods for testing
end
target 'BandApp_MusicPlayerUITests' do
# Pods for testing
end
end发布于 2021-02-17 23:04:13
您的AlbumArt结构定义是ContentView结构的内部定义,因此从PlayerView的角度来看,它超出了范围。您也可以对SongCell进行同样的操作,您不必在ContentView结构中定义它。
如果您将该struct定义移动到您的快速文件的根级别,它将编译。
struct ContentView: View {
// all your ContentView stuff
}
struct AlbumArt : View {
// this definition here
}发布于 2021-02-17 21:54:21
我想我看到了问题--您的AlbumArt类中有占位符代码:
/*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/
它出现在代码的这一部分中:
if isWithText == true {
ZStack {
Blur(style: .dark)
Text(album.name).foregroundColor(.white)
}.frame(height: 60, alignment: .center) <--- RIGHT HERE
}如果这能解决问题请告诉我!
https://stackoverflow.com/questions/66247408
复制相似问题