Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIAlertView dismissal in non-portrait orientations #60

Closed
gorbster opened this issue Aug 11, 2011 · 10 comments
Closed

UIAlertView dismissal in non-portrait orientations #60

gorbster opened this issue Aug 11, 2011 · 10 comments

Comments

@gorbster
Copy link

I'm running into issues with UIAlertViews not being dismissible in device orientations other than UIDeviceOrientationPortrait. If the device is in UIDeviceOrientationPortrait, I can easily dismiss the alert with:

[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Dismiss"];

However, this doesn't work for any other orientation, including UIDeviceOrientationPortraitUpsideDown.

The problem seems to be that _UIAlertOverlayWindow always considers itself in regular portrait orientation.

So the -convertRect:toView: call on the UIThreePartButton's window in +stepToTapViewWithAccessibilityLabel:value:traits: returns a frame with bogus coordinates and an inverted size, which is never a tappable point.

I've got a workaround for this by ensuring that the -convertRect:toView: happens on an application window with a windowLevel of UIWindowLevelNormal, i.e. always doing the -convertRect:toView: in the application's "main" window. But I wanted to see if anyone else could confirm this issue.

I have a sample project at http://dl.dropbox.com/u/33175/LandscapeAlert-KIF.zip - if you run the project in different simulator orientations, you should see the issue.

-Brian

@haemi
Copy link

haemi commented Feb 8, 2012

I can confirm this issue; how does your workaround look like exactly?

@gorbster
Copy link
Author

gorbster commented Feb 8, 2012

I have a branch with a proposed fix. Can you give it a try and let me know if it works for you?

Here's the fix:

gorbster@25fecde

Here's the branch:

https://github.com/gorbster/KIF/tree/handle-transformed-windows

@haemi
Copy link

haemi commented Feb 9, 2012

I'm afraid it's not 100% right - it looks better and promising, but it's not perfect.

Please find attached a test project at

http://dl.dropbox.com/u/119600/transfer/KIF.zip

In that app, I made an iPad app with loooots of 5x5 UIButtons, containing a title representing their position, e.g. the UIButton with the CGRectFrame(50, 120, 5, 5) contains the title "50 120".

Now, I did a test which taps the app at position

  1. 20, 30
  2. 100, 150
  3. 200, 300

And the buttons at those positions are

  1. 30 725
  2. 150 645
  3. 300 545

Thanks a lot for your help, it's really appreciated!

@gorbster
Copy link
Author

Your sample project doesn't seem demonstrate an issue with KIF.

You're using +stepToTapScreenAtPoint: to tap your buttons. This method operates at the UIWindow level, not the UIView level. The coordinate system for UIWindow is always portrait, so the taps' coordinates are never converted to the device orientation.

What you probably want to look at is +stepToTapViewWithAccessibilityLabel. Remember that KIF works around the concept of accessibility labels assigned to your view elements.

I modified your scenario code to the following:

[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"20 30"]];
[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"100 150"]];  
[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"200 300"]]; 

And added an accessibilityLabel string to your buttons:

button.accessibilityLabel = button.titleLabel.text;

And the KIF test results look accurate:

Integration Tests[22946:f803] ---------------------------------------------------
Integration Tests[22946:f803] BEGIN SCENARIO 1/1 (3 steps)
Integration Tests[22946:f803] Test that a user can successfully log in.
Integration Tests[22946:f803] ---------------------------------------------------
Integration Tests[22946:f803] 20 30
Integration Tests[22946:f803] PASS (2.23s): Tap view with accessibility label "20 30"
Integration Tests[22946:f803] 100 150
Integration Tests[22946:f803] PASS (1.21s): Tap view with accessibility label "100 150"
Integration Tests[22946:f803] 200 300
Integration Tests[22946:f803] PASS (1.16s): Tap view with accessibility label "200 300"
Integration Tests[22946:f803] ---------------------------------------------------
Integration Tests[22946:f803] END OF SCENARIO (duration 4.61s)
Integration Tests[22946:f803] ---------------------------------------------------

@haemi
Copy link

haemi commented Feb 10, 2012

Sorry, I confused the issues... I thought we're in this one here: #112

Your fix works; it's important to use the window with windowLevel normal, otherwise there are problems when e.g. a UIAlertView is currently displayed.

@msmollin
Copy link

Did this end up getting merged? I'm currently having the same issue and while I've got no problem patching our version I'd prefer not to deviate too far from master :)

@modocache
Copy link

Currently experiencing the same issue. Is there a reason this is an issue, not a pull request? Or is there some problem with the proposed fix?

@mflint
Copy link
Contributor

mflint commented Oct 16, 2012

+1 for this patch. Works fine for me too!

I'd be very happy to see this pulled.

(Thanks Brian!)

@jxa
Copy link

jxa commented Oct 26, 2012

+1

This patch fixes issues for me.

bnickel added a commit that referenced this issue Sep 12, 2013
The following method should provide hours of fun:

    [system
simulateDeviceRotationToOrientation:UIDeviceOrientationLandscapeLeft];

I used this to validate and fix issues #60 using the approach outlined
in that issue.
@bnickel
Copy link
Contributor

bnickel commented Sep 12, 2013

Fixed in master. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants