I have a scrollView
that has a UIView
as subview. This has as UIView
subview a UIButton
. Only the scrollView
is connected to the outlet, the rest is all in code. The button does not respond to touches, not turns blue when touched. What can I do to make it work?
This is the code:
- (void)viewDidLoad
{
[super viewDidLoad];
//......
self.buttonHome = [UIButton buttonWithType:UIButtonTypeCustom];
[self.buttonHome addTarget:self action:@selector(pressedHome:)
forControlEvents:UIControlEventTouchUpInside];
//....
self.containerView =[[UIView alloc]initWithFrame:self.scrollView.frame];
self.containerView.userInteractionEnabled=YES;
[self.scrollView addSubview:self.containerView];
[self.containerView addSubview:self.buttonHome];
}
-(void) pressedHome:(id)sender{
//....
}
You must set content size of your view. That must be greater than or equal to the content size of scrollView.
Because default size of your view is 320*480 (3.5" retina) and 320*568 (4" retina). So increasing height of view as-
self.view.frame=CGRectMake(0, 0, 320, 700);
Then adding this as the subview of your scrollView.
will get you to the solution.
I resolve it
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return ![view isKindOfClass:[UIButton class]];
}
Since the problem is to put a button UIButton
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With