iOS7 - Setting selectedIndex of UITabBarController breaks touch events along right-hand edge of screen?

John Martin

I've hit a weird problem with UITabBarController on iOS7 and can't seem to find a workaround, so any help would be welcome!

Scenario:

  • Navigation-based app using landscape orientation on iPad.
  • App consists of a main view, and a second view which is a UITabBarController.
  • TabBarController has two tabs.
  • First view has two buttons - each button performs a segue to the tab bar controller and sets a different tab as selected. (i.e. button1 selects the first tab, and button2 selects the second tab).
  • Setting the tab is done in prepareForSegue by calling setSelectedIndex on the tab bar controller.

Simple storyboard that demonstrates the issue

Outcome:

On iOS 7 I am finding that the view shown in the tab bar controller fails to register any touch events along the right-hand edge of the view! So in the storyboard shown above, the UISwitch on the right side of the screen cannot be tapped.

I've even attached a tap gesture recognizer to the views and used it to log the area of the screen that can be touched - it seems to register touch events up to about x=770 points across. The remaining 1/4 of the screen is 'untouchable'!

After the segue, if you manually switch to the other tab and switch back again, the touch events are 'fixed' and the full view responds to touches again.

This doesn't seem to be a problem on iOS 5 / 6.

Any help much appreciated as to:

  1. What is causing this to happen in the first place (iOS7 bug / change?)
  2. How else can I work around this? I've tried calling setSelectedViewController as well as using setSelectedIndex and this seems to be the same.

Thanks in advance.

John Martin

I ended up raising this with Developer Tech Support, and it looks like a bug. This is the response I got back from Apple:

The container view that the tab bar controller sets up to contain your view controller is not being resized to account for the interface being in landscape orientation. It's dimensions at the time your view controller is displayed are 768 (width) x 1024 (height).

The view hierarchy looks like this when the selected tab's view is displayed:

UIWindow
    /* Navigation Controller */
    UILayoutContainerView
        UINavigationTransitionView
            UIViewControllerWrapperView
                /* Tab bar controller */
                UILayoutContainerView
                    UITransitionView
                        UIViewControllerWrapperView <-- Incorrectly sized.
                            /* MyViewController */
                            MyViewController.view

The incorrect size of UIViewControllerWrapperView does not cause a display problem because subviews are still displayed even if they are outside their superview's bounds. However, event routing is much more strict. Events on the right quarter of the screen are never routed to your view controller's view because the hit test fails at the wrongly-sized UIViewControllerWrapperView where the event falls outside UIViewControllerWrapperView's bounds.

As a workaround, I subclassed UITabBarController, and added the following in viewWillAppear:

@implementation FixedIOS7TabBarController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // Fix the frame of the UIViewControllerWrapperView
    self.selectedViewController.view.superview.frame = self.view.bounds;
}

@end

Hope that helps someone else....

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Prevent touch events on subviews of scrolling UIScrollView in iOS7

From Dev

How to lift a finger from a touch screen without generating touch events?

From Dev

iOS7 - UITabBarController seletedIndex crash

From Dev

iOS7 SKScene how to make a sprite bounce off the edge of the screen?

From Dev

UINavigationController and Touch Events in Left / Left-Bottom Corner of Screen

From Dev

Handling Hover Events on a Touch Screen

From Dev

Programmatically setting UITabBarController's viewControllers and selectedIndex results in no selected UITabBarItem

From Dev

On orientation change touch events recognized for half the screen(portrait width)

From Dev

UITabbarController selectedIndex and selectedViewController do not work

From Dev

Screen freezes and does not recognize touch events

From Dev

About variables and screen touch events

From Dev

ReactJS Touch Events and iOS Safari

From Dev

Inject touch screen events, Android 5.0 , dev/input/eventX

From Dev

How do I Emulate touch events without using touch screen

From Dev

DOM touch events on IE/EDGE instead of mousedown

From Dev

iOS: KILabel not responding to touch events

From Dev

Disable touch events on certain areas of iPhone screen

From Dev

Programmatically setting UITabBarController's viewControllers and selectedIndex results in no selected UITabBarItem

From Dev

UITabbarController selectedIndex and selectedViewController do not work

From Dev

Screen freezes and does not recognize touch events

From Dev

ReactJS Touch Events and iOS Safari

From Dev

Windows 7 touch screen single touch problems

From Dev

Splitting game screen into right and left touch?

From Dev

touch left / touch right events in reagent

From Dev

DOM touch events on IE/EDGE instead of mousedown

From Dev

Touch on screen while ScrollViewer.ChangeView is active breaks app UWP

From Dev

Stretch right sidebar background to the right edge of the screen

From Dev

Strange mouse pointer behavior along right edge of screen Ubuntu 19.10

From Dev

Adding a UIBarButton in the bottom right hand side of the screen

Related Related

  1. 1

    Prevent touch events on subviews of scrolling UIScrollView in iOS7

  2. 2

    How to lift a finger from a touch screen without generating touch events?

  3. 3

    iOS7 - UITabBarController seletedIndex crash

  4. 4

    iOS7 SKScene how to make a sprite bounce off the edge of the screen?

  5. 5

    UINavigationController and Touch Events in Left / Left-Bottom Corner of Screen

  6. 6

    Handling Hover Events on a Touch Screen

  7. 7

    Programmatically setting UITabBarController's viewControllers and selectedIndex results in no selected UITabBarItem

  8. 8

    On orientation change touch events recognized for half the screen(portrait width)

  9. 9

    UITabbarController selectedIndex and selectedViewController do not work

  10. 10

    Screen freezes and does not recognize touch events

  11. 11

    About variables and screen touch events

  12. 12

    ReactJS Touch Events and iOS Safari

  13. 13

    Inject touch screen events, Android 5.0 , dev/input/eventX

  14. 14

    How do I Emulate touch events without using touch screen

  15. 15

    DOM touch events on IE/EDGE instead of mousedown

  16. 16

    iOS: KILabel not responding to touch events

  17. 17

    Disable touch events on certain areas of iPhone screen

  18. 18

    Programmatically setting UITabBarController's viewControllers and selectedIndex results in no selected UITabBarItem

  19. 19

    UITabbarController selectedIndex and selectedViewController do not work

  20. 20

    Screen freezes and does not recognize touch events

  21. 21

    ReactJS Touch Events and iOS Safari

  22. 22

    Windows 7 touch screen single touch problems

  23. 23

    Splitting game screen into right and left touch?

  24. 24

    touch left / touch right events in reagent

  25. 25

    DOM touch events on IE/EDGE instead of mousedown

  26. 26

    Touch on screen while ScrollViewer.ChangeView is active breaks app UWP

  27. 27

    Stretch right sidebar background to the right edge of the screen

  28. 28

    Strange mouse pointer behavior along right edge of screen Ubuntu 19.10

  29. 29

    Adding a UIBarButton in the bottom right hand side of the screen

HotTag

Archive