2016-10-15 13 views
0

我想知道如果有人知道如何執行一個命令,當用戶雙擊主頁按鈕和/或當按下它來到主屏幕。 Snapchat做到這一點,因爲它模糊了,當雙拍了拍背景或駁回視圖控制器,如果你走出去,回。當應用切換器出現執行命令Xcode swift

使用的Xcode 7.3.1有可能的話可以在代碼是雨燕2.2或2.3

謝謝 問候,

回答

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. 
} 
0

PLZ使用您的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. 
    }