I have the following UIVIew architecture (x,y,width,height) :
- MainWindow (0,0,768,1024)
- MainView (0,0,768,80)
- containerview (500,40,120,80)
- subview (500,40,120,80)
-some buttons
My problem is that the bottom of the subview lay outside of the bound of MainView. Buttons at the bottom of subview are not responsive. The one at the top are responsive, because their position is also inside on Mainview.
So when i try to click the buttons at the bottom of subview i actually click on MainWindow! Position of bottoms buttons of subview are not inside of MainView
Is there a way to make all my subview available even if half of it is outside of MainView bound?
I know that i can create the subview directly under MainWindow instead, but i don't want to redo my code.
Update
Here how is design my views :
A = MainWindow, B = MainView, C = container view, D = subview, X = where i want to click
+----------------------------+
|A |
|+-------------------------+ |
||B | |
|| +----------+ | |
|+------------|C&D |-+ |
| |X | |
| +----------+ |
+----------------------------+
THank you
You need to implement hitTest:(CGPoint)point withEvent:(UIEvent *)event
in your MainView.
See the documentation
Points that lie outside the receiver’s bounds are never reported as
hits, even if they actually lie within one of the receiver’s subviews.
Subviews may extend visually beyond the bounds of their parent if the
parent view’s clipsToBounds property is set to NO. However, hit
testing always ignores points outside of the parent view’s bounds.
Addressing a comment:
You should subclass UIView. Then set the class of MainView in the nib to your UIView subclass.
Some hittesting is discussed here, but I wasn't able to find clear explanation of how it works.
Try this StackOverflow question
I haven't tested it, but the following code might do what you need:
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
for(UIView *subview in self.subviews)
{
UIView *view = [subview hitTest:[self convertPoint:point toView:subview] withEvent:event];
if(view) return view;
}
return [super hitTest:point withEvent:event];
}
I'm not 100% sure I understand what you are trying to do, but if the subview is visible but not within the MainView then the only way to get actions from subview to MainView is to receive them in the subview and pass them onto MainView.
If that isn't an answer I need more information on what you are trying to accomplish.
I just solved this myself. Like you, my 'B' view launched my 'C' view and portions of 'C' outside of 'B' were unavailable.
My solution was slightly different because in my case 'C' was totally outside of, but bound to, 'B' (and was opened by 'B').
In my case, I simply attached 'C' to 'A' and made use of @property callbacks to communicate changes in 'C' with 'B' (via 'A').
In your case, another solution would be to simply extend the frame of 'B' to encompass 'C' - you can extend it back once 'C' is no longer visible. Make the background of 'B' to be clear.