Post

Replies

Boosts

Views

Activity

Need help getting two HStack views to be the same size based on one of them
Hi there! I am trying to get two HStack views with the same ZStack parent to be the same size where one of the HStack views dictates the size. This works, initially, but there's a bug that I just can't seem to find a solution for. I posted this somewhere else with images to show what is happening, unfortunately I can't do that here so I'm hoping the code and explanation will be sufficient to get a clear picture of what's going on. I have a CardView that looks like this: @State private var cardDimension = CGSize.zero var body: some View { 		ZStack { 		 				/* This HStack is for the swipe action markers */ 				HStack {...} 					.frame(width: cardDimension.width, height: cardDimension.height) 				/* This HStack has the content and dictates the size */ 				HStack {...} 					.background( 							GeometryReader { geo in 									Text("") 											.onAppear(perform: { 													self.cardDimension = geo.size 									}) 							} 					) 		} } The CardView is being rendered inside a LazyVStack within a Scrollview like so: NavigationView { ZStack { 		Color("backgroundPrimary") 		 .ignoresSafeArea(.all) 		ScrollView { ForEach(items) { item in CardView(item: item) } } } } This works and has the desired result. However, this is where things get interesting. On the bottom side of the screen, I want to add a button. This is easy enough, we're in a ZStack so all it needs is some alignment and we're good to go. So the code looks like this: NavigationView { ZStack { Color("backgroundPrimary") .ignoresSafeArea(.all) ScrollView { ForEach(items) { item in CardView(item: item) } } /* This View has the button */ VStack {...} } } What happens now is that the first CardView inside the ScrollView no longer measures its size correctly and has a lot of height and a little width. The weird thing about this is that all the cards work perfectly fine except for the very first one. Removing the card will ensure the view that is now the first view has the desired result, however reloading the application has the bug again. It all works until I add the button on the bottom of the screen, that's when it all goes south. I've tried using PreferenceKeys instead, no luck there. I'm a bit lost now and I can't seem to figure this out. Any help would be much appreciated!
1
0
772
Oct ’20
Xcode 12 / iOS14 Core Data setup
Hi there, I'm trying to figure out how to add support for Core Data to an existing project. Looking at the template that Xcode creates it is my understanding that all you need is: NSPersistentContainer(name: "dataModelName") The extra boilerplate code is mainly for previews or am I on the wrong track there?
2
0
1.1k
Sep ’20
Animation.repeatCount() for .offset suggestions
Hey there! I'm trying to make an animation repeat itself when setting an offset. I want the offset to animate 3 times with autoreverse, but it doesn't seem to have the same effect as with scaleEffect() for example. My initial thought was: Button(action: { self.offsetX -= 10 }) { Text("Tap me") } .offset(x: self.offsetX) .animation(.default) .repeatCount(3, autoreverse: true) But it simply doesn't work that way. Any suggestions / thoughts on what could work?
1
0
405
Aug ’20