IPhone - UIbutton, nested in UIView, does not respond to the following animations of this kind

I have a UIView (view B) with a UIButton on it.

I add this view B to my main view (view A) in the area outside the borders of the main view, and I, than the animation, with the UIView animation.

After the UIView animation is completed, and View B is now on top of View A, so the button is visible, the button does not respond to touches ... I have never seen this before, but this is the first application I make with the new iOS (iOS 5 ) Any ideas?

Thanks in advance.

+6
source share
3 answers

Is this the situation you are describing? Because it works fine. Have you checked if userInteractionEnabled is set to YES in UIView?

- (void)buttonPressed:(UIButton*)button { NSLog(@"button pressed"); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, -100, 100, 100)]; view.backgroundColor = [UIColor blackColor]; UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Button" forState:UIControlStateNormal]; button.frame = CGRectMake(0, 10, 100, 20); [view addSubview:button]; [self.view addSubview:view]; [UIView animateWithDuration:0.5 animations:^{ view.transform = CGAffineTransformMakeTranslation(0, 100); }]; [view release]; } 
+2
source

I'm not sure if this was answered, so I give him a chance, just for the record:

Make sure the buttons are not beyond any supervision.

I found that a button located outside of this may not work. Think about it, this is strange. I came across this when I pretended to have buttons that enliven from the bottom. Underneath this, I have a gray, tangible view that lets you undo. The only problem was that 1) for the gray area, I used the parent view and 2) I let this gray area shrink when the subtask is animated in place ... so that as a result, the buttons became outside, and that didn't work.

The solution was to leave the view in full size and add as gray, or make the first gray and not decrease (the only reason I wanted to avoid this was that it would create a bunch of translucent layers, which is not optimal ) Then a view with buttons on top. :)

Hope this helps.

+1
source

If you created the button through programming, you need to do the following: -

 myButton.userInteractionEnabled =YES; 

Hope this helps ... :)

0
source

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


All Articles