I'm just starting out learning about iOS GUI after playing around with backend stuff and Objective-C in general the last few weeks. I've stumbled upon a tricky situation that I've managed to solve but I want to know if there is a better way to solve it.
Here's how I've layered my UIViews:
[self.view.layer insertSublayer:_topView.layer above:self.view.layer];
[self.view.layer insertSublayer:_bottomView.layer above:self.view.layer];
So I have the "base" view and a single ViewController. In this view I have two subviews: topView and bottomView. I have been able to manipulate the origin of these views just like I want but even when they are in front of my UIButton it reacts to touch.
I solved this by checking the y axis of the origin of one of the subviews (it doesn't matter which one) to make sure that the button is revealed and thus activate it (or enable user interaction, rather).
if (_topView.frame.origin.y == 0) {
self.refreshButton.userInteractionEnabled = NO;
} else {
self.refreshButton.userInteractionEnabled = YES;
}
I personally dislike this solution and would like to know what a better way to solve this is.
Can anyone point me in the right direction so that I get this layer business going without ugly hacks here and there?
I am using storyboards with Xcode 5.0.
Cheers!