Orientation without animation giving weird result when UIAlertView is present
Asked Answered
S

3

10

I am facing a weird problem here.

For some reason I am disabling the animation during orientation change in my view controller using [UIView setAnimationsEnabled:NO];
But when the alert view is present and if I change the orientation then it is giving weird result.

The attached screen shot is when I change the orientation to landscape.

landscape mode

Please note: I am using standard UIAlertView and it is default overlay which is shown when the alert view is present and there is no customisation involved here.

As per the documentation

If you disable animations, code inside subsequent animation blocks is still executed but no animations actually occur. Thus, any changes you make inside an animation block are reflected immediately instead of being animated.

So it should not affect the resizing of the default overlay. Is it a restriction in disabling animation !??

I am not understanding why I am getting like this. Could anyone please help in solving this.

Svetlana answered 29/5, 2013 at 6:20 Comment(6)
So you are first displaying a UIAlertView and then rotating the device, right? Or displaying it during the rotation?Lucie
I am displaying UIAlertView and then rotating the device.Svetlana
It's rather strange because as far as I can remember, when UIAlertView is displayed, the rotation is disabled automatically.Lucie
@SergiusGee No, the rotation is not disabled when UIAlertView is present. I have checked that in normal senario also. If I remove [UIView setAnimationsEnabled:NO]; everything works well.Svetlana
Are you showing alert view in main thread? If not show it in main threadPennsylvania
Yes, I am showing it in main thread.Svetlana
S
0

This seems to be a bug in iOS6 and below and is fixed in iOS7.

iOS alert view without animation

Svetlana answered 7/10, 2013 at 12:25 Comment(0)
O
4

When you set [UIView setAnimationsEnabled:NO];, UIAlertView is not resizing it's Overlay View (I think it's a bug).

Optionally you can restrict orientation when alert view is on screen as following.

Create a BOOL variable in .h file.

BOOL shouldRotate;

initialize it with YES in viewDidload.

And whenever you show alert at that time make shouldRotate = NO;

And implement UIAlertView delegate as follows:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    shouldRotate = YES;
}

Hope will help you.

Edit: As you want both no animation and rotation with alert view

This is actually a hack but works,

alert is an UIAlertView's object declared in .h file.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if (UIInterfaceOrientationPortrait == UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) {
        UIImageView *imgView = (UIImageView *)[alert.superview.subviews objectAtIndex:0];
        imgView.frame = CGRectMake(0.0, 0.0, 480.0, 320.0);
    }
    else{
        UIImageView *imgView = (UIImageView *)[alert.superview.subviews objectAtIndex:0];
        imgView.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
    }
}
Orv answered 4/6, 2013 at 12:55 Comment(3)
Thanks for your answer, I know this alternative but I need to give both, so I cant use this.Svetlana
Actually UIAlertView manages it's overlay view with transform animation (As per my debug of UIAlertView), and when you disables animation for UIView this part doesn't get executed and overlay view is not resizing as per the need.Orv
@prasaddevadiga I have edited my answer and it should solve your problem.Orv
C
3

Another possibility to cope with this bug would be to dismiss the alert view programmatically before rotation and displaying a new one after rotation completed.

That would automatically work for any iOS device independent of screen size.

Cloche answered 7/6, 2013 at 21:1 Comment(0)
S
0

This seems to be a bug in iOS6 and below and is fixed in iOS7.

iOS alert view without animation

Svetlana answered 7/10, 2013 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.