I am attempting to get a UIButton's y coordinate position through the stack view that it belongs to. I need this value in the program to map the position of the button to a different coordinate system.
Here is my code that will grab the button's y-value from the stack view:
p_tilePosition.x = round(self.layer.position.x / (self.frame.size.width + 8.0))// The 8 here is the standard spacing between sibling views
let testView = self.superview
if let yPosition = self.superview?.layer.position.y{
p_tilePosition.y = round(yPosition / (self.frame.size.height + 8.0))
}
(Note that this is in a subclass of the UIButton. When the UIButton is inilized, it will run through this code to create the mapping)
However, I have found out that the self.superview is nil. I am confused by this because I thought that the superview of the button is the stack view that the button is in? Is this not the case? How would I be able to get the button's y-position by getting the stack's y-position on initialization?