繁体   English   中英

检测何时按下主页按钮

[英]Detect when home button is pressed

在我的应用中,当用户按下主页按钮时,我需要隐藏UIImageView。 我尝试使用pressesBegan(_:with :),但从未打电话。 有谁知道如何检测按下主页按钮的时间?

@IBOutlet weak var shouldHideView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.  
}

func hide(){
    self.shouldHideView.isHidden = true
}

override fun pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?){ 
    self.hide()
}

通常,您要使用的工具是UIApplicationDelegate.applicationWillResignActive(_:) 与按下“主页”按钮时相比,这种调用的频率要高一些,但是通常这就是您的实际意思。 当按下主页按钮时, 可以拨打电话。)

据我所知,主页按钮按下事件在iOS SDK中不可用。 您可以使用以下任何UIApplicationDelegate方法来观察应用程序何时进入后台:

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

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Tells the delegate that the app is now in the background.
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM