Iphone 如何在iOS 7中以编程方式正确关闭UIAlertView?

Iphone 如何在iOS 7中以编程方式正确关闭UIAlertView?,iphone,ios,ios7,uialertview,Iphone,Ios,Ios7,Uialertview,当我的应用程序进入后台时,我的模式显示视图控制器会关闭一个警报视图,就像这样 // called when view controller receives a UIApplicationDidEnterBackgroundNotification - (void)applicationDidEnterBackground:(NSNotification *)notification { if (self.alertView) { [self.alertView dism

当我的应用程序进入后台时,我的模式显示视图控制器会关闭一个警报视图,就像这样

// called when view controller receives a UIApplicationDidEnterBackgroundNotification
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
    if (self.alertView) {
        [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
        self.alertView = nil;
    }
}
当我的应用程序返回前台而未终止时,警报视图将消失。但是,导航栏(来自UINavigationController)中的栏按钮项目仍会变暗,就好像警报视图仍在显示一样

此外,解除模式视图控制器(通过点击变暗的条形按钮项)会显示显示视图控制器的条形按钮项也变暗。条形按钮项可以正常工作,但仍保持暗显状态

那么,如何取消条按钮项的暗显?或者,我如何在iOS 7中以编程方式正确关闭警报视图,以响应进入后台的应用程序

《iOS 7用户界面转换指南》说明了以下内容:

当警报或行动表出现时,iOS 7会自动使其后面视图的色调变暗。要响应此颜色更改,在渲染中使用tintColor的自定义视图子类应覆盖tintColorDidChange以在适当时刷新渲染

我的导航栏和栏按钮项不是自定义视图;我没有把它们分类。我在故事板中创建了带有默认属性的导航栏(与栏按钮项相同)。所以我没有地方去改变

“我的所有视图”的“着色颜色”属性都使用默认值

我已尝试将着色颜色重新设置为默认值,但未成功:

if (self.alertView) {
        [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
        self.view.tintColor = nil;
        self.view.window.tintColor = nil;
        self.alertView = nil;
    }
if (self.alertView) {
    [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
    self.alertView = nil;

    self.view.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
}
我还尝试在视图控制器的ViewDidDisplay:中重新设置着色颜色,但未成功

我还尝试将主视图的tintAdjustmentMode设置为“正常”,但没有成功:

if (self.alertView) {
        [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
        self.view.tintColor = nil;
        self.view.window.tintColor = nil;
        self.alertView = nil;
    }
if (self.alertView) {
    [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
    self.alertView = nil;

    self.view.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
}

顺便说一句,如果应用程序在后台被终止,应用程序将使用具有正确色调(即未变暗)的条形按钮项重新启动。

尽管我可以通过编程方式关闭警报视图以响应
UIApplicationIdentinterBackground通知
,iOS 7中的自动色调调暗将不会得到更新

但是,如果我关闭警报视图以响应
UIApplicationWillResignActiveNotification
,则自动着色变暗行为将响应

// called when view controller receives a UIApplicationWillResignActiveNotification
- (void)applicationWillResignActiveNotification:(NSNotification *)notification
{
    if (self.alertView) {
        [self.alertView dismissWithClickedButtonIndex:0 animated:NO];
        self.alertView = nil;
    }
}

我很确定这是苹果的一个缺陷。我已经在提交了一份错误报告,请提交一份重复的错误报告,让苹果公司注意它。

我在我的应用程序中遇到了相同的错误,并成功找到了解决方法。在后台关闭UIAlertView后,只需在应用程序的主窗口上将tintAdjustmentMode设置为UIViewTintAdjustmentModeNormal。简单:)

我的警惕性视图一直在从后台过渡,这让我很沮丧。我还将进一步了解这一点。使用
[[UIApplication sharedApplication]keyWindow]
,检查当前活动的窗口是什么。由于UIAlertView有自己的窗口,可能是该窗口没有正确关闭,使您的栏(按钮项)变暗。您还可以尝试在应用程序再次激活之前将其关闭(
application:willEnterForeground:
)。这似乎更准确。如果操作系统在后台关闭modals,那么它应该完全关闭modals。同时,你可以使用标准的
dismissWithClickedButtonIndex:animated:
在你的应用程序被发送到后台之前关闭它。这方面有什么进展吗?你仍然应该提交一个类似@Mohamed所说的错误。记住,打开控制中心和通知中心会导致你的应用程序退出活动状态,并将导致解除警报。这不是最佳行为。请考虑使用SGOHA的解决方案。在iOS 7上,当警报显示在屏幕上时,我无法从边缘滑动以显示控制中心或通知中心。这是一个很好的观点,但你仍然可以获得操作系统警报,这也会使你的应用处于非活动状态。你说的是do
self.view.tinadjustmentmode=uiviewtinadjustmentmodenormal对吗?我试过了,但它对我不起作用,你是在
applicationidentinterbackground
(这就是我试过的),还是在你重新进入前景时做的?@MohamedHafez我在-[UIAlertView dismisswithclickedbutonnindex:animated:]