Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 UI Transition issue: Touch events ignored at bottom of screen

I'm currently fixing an issue in an old app (built in the days of iOS 5) where button touch events are ignored at the bottom of the screen. I am able to recreate this issue by creating a new project, deleting the storyboard (and the reference in the Info plist), and doing the following in didFinishLaunchingWithOptions (I know this isn't the correct way to do, but this app i'm working on has a similar setup)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
    self.window.screen = [UIScreen mainScreen];

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor yellowColor];
    self.window.rootViewController = vc;

    UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [test setTitle:@"Hey" forState:UIControlStateNormal];
    [test setBackgroundColor:[UIColor whiteColor]];
    test.frame = CGRectMake(0, 824, 200, 200);
    [vc.view addSubview:test];

    [self.window makeKeyAndVisible];

    return YES;
}

Once I run this app, the "Hey" button only works by depressing the upper half of it. I have a feeling it's related to the iOS 7 status bar, and how the UI now goes underneath it rather than below it. I tried adjusting the window's bounds, but that doesn't help. I've tried all sorts of things to get this button to work, but the only thing that works is hiding the status bar.

Anyone have any clues how to get that button working in this situation?

like image 286
Felix Khazin Avatar asked Jan 23 '14 19:01

Felix Khazin


1 Answers

I don't think the events are being ignored - I think it's just that the button highlight feedback isn't being displayed for button presses at the bottom of the screen in iOS7

Using your example, add this to didFinishWithLaunching in AppDelegate.m

[test addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

And then add this method to AppDelegate.m

-(void)buttonPressed:(id)sender{
    NSLog(@"hey!");
}

Tap at the bottom edge of the button and you'll see the action method called even though the visible feedback isn't shown.

Oddly, if you press and drag in any direction the visual feedback shows correctly.

like image 144
john Avatar answered Sep 17 '22 20:09

john