tags:

views:

46

answers:

1

I am working on a landscape view iPhone application. I rotate the view, then add another view inside it, which I call "horizontalView" in the code below. After adding this, I re-center it to the middle. This works fine to re-center correctly, but the trouble is that, my buttons in the mainView starts not working.

 // Add the horizontal controller
 HorizontalContainerViewController* c = [[HorizontalContainerViewController alloc]
                       initWithNibName:@"HorizontalContainerViewController"
           bundle:nil];
 self.horizontalView        = [c view];
 self.horizontalView.center = CGPointMake(160, 240); // <----  PROBLEM HERE
 [containerView addSubview:horizontalView];

 // Initially show the main view
 self.mainViewController = [MainViewController createFor: self];
    [self.horizontalView addSubView:self.mainViewController];

If I remove the line marked "PROBLEM HERE", my buttons inside mainViewController.view work fine. If I add this one line, they start not responding to my touch. What might be going on here?

EDIT: By the way... I noticed that some buttons closer to the edge of the view don't work, whereas some buttons in the middle of the view are working just fine.

Thanks,

-Steve

A: 

I figured this out. It seems that, on iPhone app, if the bottom-most view does not cover some portion of the window area, that area basically does not accept "touch" events.

E.g you have 320x480 window area
    you add a view of 320x480 to the window, which originally covers the same area
    you rotate the view 90 degree left
    Now, you have a vertical view that only covers the middle portion of the window area.
    Something like:

    |--------|
    |        |
----+--------+----
|   |        |   |<-- your window area
| B |   A    | C |
|   |        |   |
----+--------+----
    |        |<-- rotated view (your bottom-most view)
    |--------|

Then, you add additional subviews to eventually cover the whole landscape area. (A + B + C) However, since your original view didn't cover B and C areas, any controls that happen to get placed in areas B and C will not get the touch events.

In my case, when I set center property, some existing buttons fell into an uncovered area like B or C in the picture above. That's why some buttons that used to work started not working.

Lessons learned:

1) It's not a good idea to rotate the bottom-most view that you added to the window

2) (I didn't try this but) It'd be helpful to set "clip subvies" on the bottom-most view so that you notice if some areas of your screen is likely to not process touch events.

-Steve

AdvilUser