This is an example view:
I want to calculate a frame with a CGPoint
where I can spawn another card(UIView
) without touching any existing card. Ofcourse it is optional since the view can be full of cards, therefore there is no free spot.
This is how I can see any card on the screen and my function how it is now:
func freeSpotCalculator() -> CGPoint?{
var takenSpots = [CGPoint]()
for card in playableCards{
takenSpots.append(card.center)
}
}
I have no idea where to start and how to calculate a random CGPoint
on the screen. The random frame has the same width
and height
as a card in on the screen.
As I can see in the picture all your cards are aligned at the bottom of the View. so if you generate a random y position from
0 to origin of your cards row - one card height
you can simply get a CGPoint based on the frame of your view and size of the cards.