簡體   English   中英

當應用進入后台模式時釋放圖形

[英]Release graphics when app entered to background mode

在Apple文檔中,您可以發現Apple建議在應用程序進入后台模式時釋放大量數據,如圖像。
如何從UIViews和其他數據中釋放圖像?
如何釋放從圖像UIViews所有viewController正確的方式?
如何在app獲取applicationWillResignActive消息時恢復數據?

如果有人有一個很好的例子或鏈接,請顯示它。

添加到app delegate 2方法

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}

使用方法創建BaseViewController:

- (id)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillForeground) name:NOTIFICATION_APP_FOREGROUND object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBackground) name:NOTIFICATION_APP_BACKGROUND object:nil];
    }

    return self;
}


- (void)appDidBackground {
}

- (void)appWillForeground {

}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

從BaseViewController子類化所有視圖控制器。 在方法appDidBackground中,您應該在appWillForeground中釋放不需要的數據 - 恢復它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM