简体   繁体   English

iPhone到iPad,iPhone 4 uialertview问题

[英]iphone to ipad, iphone 4 uialertview problems

So I've upgraded the code to the ipad (ie converted to a universal app). 因此,我已将代码升级到ipad(即转换为通用应用程序)。 However, the UIAlertview rendering seems to be off for IOS4. 但是,UIAlertview呈现似乎不适用于IOS4。 Instead of being positioned in the middle, it jumps up and is displayed on top, with half the box cut off. 它跳起来而不是放在中间,而是显示在顶部,其中一半的框被切除。 Same goes for landscape orientation. 横向方向也是如此。

It is my understanding that the UIalertview is always set in the middle? 据我了解,UIalertview始终设置在中间吗? I looked through the code and I did not set up the frame/position anywhere in the code. 我浏览了一下代码,但没有在代码的任何地方设置框架/位置。 This only happens for 4.0, on both the iphone 4 and the itouch running 4.0. 这仅适用于4.0,在iPhone 4和运行4.0的itouch上均如此。 Every other version is fine, including the ipad. 其他所有版本都可以,包括ipad。 Any thoughts? 有什么想法吗?

Thanks. 谢谢。

Seems to be a bug. 似乎是一个错误。 I also had the Problem on iPad with iOS 3.2. 我在装有iOS 3.2的iPad上也遇到了问题。

Solution: 解:

a) Check your app state: In iOS 4 just use a)检查您的应用程序状态:在iOS 4中,只需使用

[UIApplication sharedApplication].applicationState

Older iOS: Store your app state manually: 较旧的iOS:手动存储您的应用状态:

-(void)applicationWillResignActive:(UIApplication *)application
{
    self.appIsInBackground = YES;
}

-(void)applicationWillTerminate:(UIApplication *)application
{
    self.appIsInBackground = YES;
}

-(void)applicationDidBecomeActive:(UIApplication *)application
{
    // Open your UIAlert here if self.appIsInBackground == YES;

    self.appIsInBackground = NO;
}

b) open the UIAlert after the app did become active, as shown above in the comments. b)在应用程序激活后打开UIAlert,如上面的注释所示。

Does your alert have any Textfields added ? 您的警报中是否添加了任何文本字段?

Because in 4.0+ iOS scrolls the alertview to visible part if you have a textfield in the alertview. 因为在4.0+中,如果您在Alertview中有文本字段,iOS会将AlertView滚动到可见部分。

I have the same problem for iPad 3.2 when application resign active and in that time alert is shown that alert will be shown on top left corner. 当应用程序重新启动时,iPad 3.2遇到同样的问题,此时显示警报,警报将显示在左上角。 So i fixed using following code in the method -(void)applicationDidBecomeActive:(UIApplication *)application 所以我在方法-(void)applicationDidBecomeActive:(UIApplication *)application中使用以下代码修复了问题

//Check that key window is alert view
if ([[[UIApplication sharedApplication].keyWindow description] hasPrefix:@"<_UIAlertOverlayWindow"]) {
    //Yes then check for subviews tht are alertViews
    UIWindow *alertViewWindow = [UIApplication sharedApplication].keyWindow;
    NSArray *subViews = [alertViewWindow subviews];
    for (UIView *subview in subViews) 
    {
        if ([subview isKindOfClass:[UIAlertView class]]) 
        {
            //Retain it
            UIAlertView *alertView = (UIAlertView *)[subview retain];
            //Now dismiss it and then show it again
            [alertView dismissWithClickedButtonIndex:0 animated:NO];//Here ClickedButtonIndex must be according to cancel button
            //Show the alert view again
            [alertView show];
            //Release previsous retained object
            [alertView release];

        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM