当app切换器出现时执行命令Xcode swift

时间:2016-10-15 11:30:35

标签: ios swift xcode

我想知道当用户双按主页按钮和/或只需按下它以进入主屏幕时是否有人知道如何执行命令。 Snapchat可以做到这一点,因为如果你再次出门,双击或解散视图控制器会模糊背景。

使用Xcode 7.3.1,如果可能,代码可以是Swift 2.2或2.3

由于 的问候,

2 个答案:

答案 0 :(得分:0)

使用您的AppDelegate方法

  func applicationWillResignActive(application: UIApplication) {
        // 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.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // 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.
    }

答案 1 :(得分:0)

Appdelegate.swift文件中,您会发现两种方法可以让您在应用从前台状态更改为后台时执行代码 - 例如按主页按钮。

func applicationWillResignActive(_ application: UIApplication) {
    // 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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

    func applicationDidEnterBackground(_ application: UIApplication) {
    // 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.
}