LoginSignup
7
7

More than 5 years have passed since last update.

画面切り替え(マルチタスク)画面でのアプリのサムネイルの切替

Posted at

パスコードロックを使用しているアプリの多くはバックグラウンドにした後、
フォアグラウンドにするとパスコード入力画面を表示できます。

バックグラウンド中に画面切り替え(マルチタスク)画面を表示すると、
パスコード入力画面ではなく、バックグラウンドにする前に
表示していた画面が見えてしまうことがあります。
2.png

パスコード入力画面を表示する方法を試行錯誤しましたので投稿します。
あくまで画面切替画面でのサムネイルを変更することだけを記載しています。
フォアグラウンドにした際にパスコード入力させるようにするには、別途実装が必要です。

■準備
・パスコード入力画面のスクリーンショット
 ※ここでは passcode@2x.png を用意しました
passcode@2x.png

■実装
・AppDelegate.hとAppDelegate.mを少し変更
// add とした部分のみ

AppDelegate.h
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic) UIImageView *passcodeSplashView; // Add
@end
AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    _passcodeSplashView = [[UIImageView alloc]initWithFrame:self.window.bounds]; // Add
    _passcodeSplashView.image = [UIImage imageNamed:@"passcode.png"]; // Add

    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

    [self.window addSubview:_passcodeSplashView]; // Add
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    [_passcodeSplashView removeFromSuperview]; // Add
}


- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


}


- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

■結果
3.png

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7