标签:ios 系统消息通知
一、键盘
1、UIKeyboardWillShowNotification-将要弹出键盘
2、UIKeyboardDidShowNotification-显示键盘
3、UIKeyboardWillHideNotification-将要隐藏键盘
4、UIKeyboardDidHideNotification-键盘已经隐藏
5、UIKeyboardWillChangeFrameNotification-键盘将要改变frame
6、UIKeyboardDidChangeFrameNotification-键盘已经改变frame
二、窗口
1、UIWindowDidBecomeVisibleNotification-窗口可见
2、UIWindowDidBecomeHiddenNotification-窗口隐藏
3、UIWindowDidBecomeKeyNotification
4、UIWindowDidResignKeyNotification
三、程序消息
1、UIApplicationDidBecomeActiveNotification-程序从后台激活
2、UIApplicationDidChangeStatusBarFrameNotification-状态栏frame改变
3、UIApplicationDidChangeStatusBarOrientationNotification-状态栏方向改变
4、UIApplicationDidEnterBackgroundNotification-进入后台
5、UIApplicationDidFinishLaunchingNotification-程序加载完成
6、UIApplicationDidReceiveMemoryWarningNotification-内存警告
7、UIApplicationProtectedDataDidBecomeAvailable
8、UIApplicationProtectedDataWillBecomeUnavailable
9、UIApplicationSignificantTimeChangeNotification重要的时间变化(新的一天开始或时区变化)
10、UIApplicationWillChangeStatusBarOrientationNotification-将要改变状态栏方向
11、UIApplicationWillChangeStatusBarFrameNotification-将要改变状态栏frame
12、UIApplicationWillEnterForegroundNotification
13、UIApplicationWillResignActiveNotification
14、UIApplicationWillTerminateNotification
四、电池、方向、传感器
1、UIDeviceBatteryLevelDidChangeNotification//电池电量
2、UIDeviceBatteryStateDidChangeNotification//电池状态
3、UIDeviceOrientationDidChangeNotification//方向
4、UIDeviceProximityStateDidChangeNotification//近距离传感器
五、音视频
1、MPMediaLibraryDidChangeNotification
2、MPMusicPlayerControllerPlaybackStateDidChangeNotification
3、MPMusicPlayerControllerNowPlayingItemDidChangeNotification
4、MPMusicPlayerControllerVolumeDidChangeNotification
六、其他
1、NSUserDefaultsDidChangeNotification用户默认设置变化
2 NSCurrentLocaleDidChangeNotification 本地化语言变化
以下为系统通知应用,在键盘弹出时,使键盘不会覆盖textField
#import "ViewController.h"
@interface ViewController ()
{
UITextField *tempTF;
}
@property (weak, nonatomic) IBOutlet UITextField *tf1;
@property (weak, nonatomic) IBOutlet UITextField *tf2;
@property (weak, nonatomic) IBOutlet UITextField *tf3;
@property (weak, nonatomic) IBOutlet UITextField *tf4;
@property (weak, nonatomic) IBOutlet UITextField *tf5;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//注册viewController为监听者,并向通知中心发送信息
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHidden:) name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark ----实现键盘弹出的方法----
//实现keyboardShow方法
-(void)keyboardShow:(NSNotification *)sender{
//打印useInfo获取键盘尺寸
NSLog(@"%@",sender.userInfo);
/*
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 253}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 694.5}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 441.5}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 253}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 315}, {320, 253}}";
UIKeyboardIsLocalUserInfoKey = 1;
*/
NSValue *rect =sender.userInfo[ UIKeyboardFrameEndUserInfoKey];
//获取键盘高度
CGFloat keyboardHeight= [rect CGRectValue].size.height;
//获取屏幕尺寸
CGFloat screen_height= [[UIScreenmainScreen]bounds].size.height;
CGFloat screen_width = [[UIScreen mainScreen]bounds].size.width;
CGFloatresult = screen_height - keyboardHeight;
//判断键盘是否挡住textField
if (result < tempTF.frame.origin.y+tempTF.frame.size.height) {
//改变view的位置
self.view.frame = CGRectMake(0, result-tempTF.frame.origin.y-tempTF.frame.size.height,screen_width, screen_height);
}
}
//实现keyboardHidden方法
-(void)keyboardHidden:(NSNotification *)sender{
CGFloat screen_height = [[UIScreen mainScreen]bounds].size.height;
CGFloatscreen_width = [[UIScreen mainScreen]bounds].size.width;
//View恢复原位置
self.view.frame = CGRectMake(0, 0, screen_width, screen_height);
}
#pragma mark ----实现textField的代理方法----
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//将textField设置为当前tempTF
tempTF =textField;
return YES;
}
//按return键盘消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
return [textField resignFirstResponder];
}
- (void)didReceiveMemoryWarning{
[superdidReceiveMemoryWarning];
}
@end