IOS 系统通知

键盘通知

UIKeyboardWillShowNotification  键盘即将显示
UIKeyboardDidShowNotification  键盘显示完毕
UIKeyboardWillHideNotification  键盘即将隐藏
UIKeyboardDidHideNotification  键盘隐藏完毕
UIKeyboardWillChangeFrameNotification  键盘的位置尺寸即将发生改变
UIKeyboardDidChangeFrameNotification  键盘的位置尺寸改变完毕

系统发出键盘通知时,会附带一下跟键盘有关的额外信息(字典),字典常见的key如下:

UIKeyboardFrameBeginUserInfoKey  键盘刚开始的frame
UIKeyboardFrameEndUserInfoKey  键盘最终的frame(动画执行完毕后)
UIKeyboardAnimationDurationUserInfoKey  键盘动画的时间
UIKeyboardAnimationCurveUserInfoKey  键盘动画的执行节奏(快慢)

例:

- (void)viewDidLoad {
    [super viewDidLoad];
     即将显示的键盘
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
/**
 *  监听键盘的即将显示
 */
- (void)keyboardWillShow:(NSNotification *)note
{
     获得键盘的frame
    CGRect frame = [note.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
    
     修改底部约束
    self.bottn.constant = frame.size.height;
 }

UIDevice

UIDevice类提供了一个单粒对象,它代表着设备,通过它可以获得一些设备相关的信息,比如电池电量值(batteryLevel)、电池状态(batteryState)、设备的类型(model,比如iPod、iPhone等)、设备的系统(systemVersion)

UIDevice对象所发布通知的名称常量:
UIDeviceOrientationDidChangeNotification  设备旋转
UIDeviceBatteryStateDidChangeNotification  电池状态改变
UIDeviceBatteryLevelDidChangeNotification  电池电量改变
UIDeviceProximityStateDidChangeNotification  近距离传感器(比如设备贴近了使用者的脸部)

程序相关

UIApplicationDidEnterBackgroundNotification 当程序被推送到后台时
UIApplicationWillEnterForegroundNotification  当程序从后台将要重新回到前台时
UIApplicationDidFinishLaunchingNotification  当程序完成载入后通知
UIApplicationDidBecomeActiveNotification   应用程序转为激活状态时
UIApplicationWillResignActiveNotification    用户按下主屏幕按钮调用通知,并未进入后台状态
UIApplicationDidReceiveMemoryWarningNotification   内存较低时通知
UIApplicationWillTerminateNotification   当程序将要退出时通知
UIApplicationSignificantTimeChangeNotification   当系统时间发生改变时通知
UIApplicationBackgroundRefreshStatusDidChangeNotification  后台下载状态发生改变时通知(iOS7.0以后可用)  
UIApplicationUserDidTakeScreenshotNotification   截屏通知
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • UIDevice UIDeviceOrientationDidChangeNotification:设备旋转UID...
    开心的小娇阅读 2,230评论 0 1
  • 转载自:http://momirror.blog.163.com/blog/static/484181842013...
    hou_8阅读 880评论 0 0
  • 当程序被推送到后台时 当程序从后台将要重新回到前台时 当程序完成载入后通知 应用程序转为激活状态时 用户按下主屏幕...
    翱翔的魁魁阅读 2,813评论 0 3
  • iOS相当多一部分系统事件实际上都是通过通知来完成的,依赖于通知的广播形式,我们可以在AppDelegate中通过...
    某天天阅读 263评论 1 0
  • 当今世界有很多前沿科技,我想说的是区块链。对,就是区块链,一个看不到摸不着的世界。 什么是区块链呢? 区块链是分布...
    感想心得阅读 152评论 0 1