Get bindings in SuperView after adding SubView

Starting with the iOS Single View template in Xcode 4.2, I added a second view to my .xib, the Super button on the main view and the Sub button in the subView. I would like to be able to press both buttons.

In the view controller interface, I added:

IBOutlet UIView *subView; 

Then, in my opinion, the controller has the viewDidLoad method, I add:

  [self.view addSubview:subView]; 

after [super viewDidLoad];

There is a “clear” background in the subView, and both windows are set to “User Interaction Enabled”.

When I launch the application, only the Sub button is available for clicks. I can see the “Super” button, but it doesn’t seem to get touches, which should be by default, as far as I can tell from the Apple documentation (transparent view areas should allow touches to go through).

+4
source share
2 answers

This is not what happens if you place the view in front of another, the rear view will not get clicked.

You can disable user interaction in fron view, so feedback will get contact.

but I think that you want the front panel and the feedback to be interactive, what you need to do in this case - touch and send it in the opposite direction and process it in the opposite direction.

I don’t know what you are trying to do, but I think you can probably do a better option than this.

You can see this question here in stackoverflow: detect a touch on a view after another view?

EDIT:

You have many opportunities to send touches.

You can do something like (this is not very good):

 -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ for (UITouch *touch in touches) { for(UIView* v in self.view.subviews){ if([v pointInside:[touch locationInView:self.view] withEvent:event]){ if ([v isKindOfClass:[UIButton class]]) { [(UIButton*)v sendActionsForControlEvents:UIControlEventTouchUpInside]; } } } } } 

You can also edit the view frame so that the view is not closed by the button.

You can also bring you a button on the front of the new view by doing something like:

 [self.view addSubview:yourSubview]; [self.view bringSubviewToFront:yourButton]; 

You just need to use your creativity;)

+3
source

- your second view of the content size (button) or the size of the entire view? it may be easier for you to simply make your subview the size of an object, not 320x480. then align it through cgrectmake after adding it as a subtitle.

that / way / is easier than bubbling up on different touches, which becomes a bit of a nightmare.

0
source

Source: https://habr.com/ru/post/1403006/


All Articles