views:

32

answers:

1

In my app there is a background on top of the window:

UIImageView *mybg = [[UIImageView alloc]
                     initWithImage:[UIImage imageNamed:@"bg_large.png"]];
[window addSubview:mybg];

then a button in top of the background:

UIButton *infoButton = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
infoButton.frame = CGRectMake(280,420,20,20);

[infoButton addTarget:self action:@selector(showInfoPanel:) forControlEvents:UIControlEventTouchUpInside];
[window addSubview:infoButton];
[infoButton release];

then a scrollview inside a navigation controller, those added to the window on the top:

    navController = [[UINavigationController alloc] init];
navController.viewControllers = [[NSArray arrayWithObject:dashboardViewController] retain];
[navController setNavigationBarHidden:YES];
myScrollView.opaque=NO;
myScrollView.backgroundColor = [UIColor clearColor];
dashboardViewController.view.backgroundColor = [UIColor clearColor];
[window addSubview:navController.view];

the scrollview respond to touches as it should, but the infoButton that added before in the top of the background doesn't. I added the infoButton to the top of the bg, to be stable and not scroll with scrollview.

How can I make the button respond to touches, as well as the scrollview together with it?

+1  A: 

U are adding UINavigationController.view on the top of button thats why it is not respoiding, Try placing the code [window addSubview:infoButton]; after [window addSubview:navController.view];.

Chandan Shetty SP
doing that the button stays on top of nav controller when the controller push another view.
kitsos
Since you are adding button to window it will not cause problem... otherwise just add [window bringSubviewToFront:infoButton] after adding view controller.
Chandan Shetty SP