iOS 在viewController中监听Home键触发以及重新进入界面的方法
2016-01-25 14:43
375 查看
第一步:
创建2个NSNotificationCenter监听
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; //监听是否触发home键挂起程序. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; //监听是否重新进入程序程序.
第二步:
实现2个NSNotificationCenter所触发的事件方法
- (void)applicationWillResignActive:(NSNotification *)notification { printf("按理说是触发home按下\n"); } - (void)applicationDidBecomeActive:(NSNotification *)notification { printf("按理说是重新进来后响应\n"); }
注: 在home键触发后,AppDelegate响应的方法为:
- (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.
*/
}
相关文章推荐
- iOS--BaiduMap自定义annotation和annotationView
- iOS获取系统时间
- iOS中解析Bonjour服务(转)
- IOS-应用之间调用
- iOS 给【控制器添加统计】的简单、使用方法
- iOS7计算文本尺寸
- IOS 真机报错,dyld:Librarynotloaded;image not found
- iOS 多个按钮选中一个
- iOS CATextLayer 富文本
- ios应用版本号设置规则
- IOS支付宝开发中的问题
- IOS支付宝开发SDK的集成
- iOS:控制器间的数据传递
- iOS第三方类库JSPatch(热更新)
- iOS文件写入读取
- IOS自定义控件系统方法调用顺序
- iOS 中如何添加应用自己的字体,使用萍方体
- 新书推荐《从Node.js到iOS学注册登录》
- iOS判断字符串中是否包含另一个字符串
- iOS经典讲解之设置颜色注意事项