系统通知

标签:ios 系统消息通知

一、键盘

1UIKeyboardWillShowNotification-将要弹出键盘

2UIKeyboardDidShowNotification-显示键盘

3UIKeyboardWillHideNotification-将要隐藏键盘

4UIKeyboardDidHideNotification-键盘已经隐藏

5UIKeyboardWillChangeFrameNotification-键盘将要改变frame

6UIKeyboardDidChangeFrameNotification-键盘已经改变frame

 

二、窗口

1UIWindowDidBecomeVisibleNotification-窗口可见

2UIWindowDidBecomeHiddenNotification-窗口隐藏

3UIWindowDidBecomeKeyNotification

4UIWindowDidResignKeyNotification

三、程序消息

1UIApplicationDidBecomeActiveNotification-程序从后台激活

2UIApplicationDidChangeStatusBarFrameNotification-状态栏frame改变

3UIApplicationDidChangeStatusBarOrientationNotification-状态栏方向改变

4UIApplicationDidEnterBackgroundNotification-进入后台

5UIApplicationDidFinishLaunchingNotification-程序加载完成

6UIApplicationDidReceiveMemoryWarningNotification-内存警告

7UIApplicationProtectedDataDidBecomeAvailable

8UIApplicationProtectedDataWillBecomeUnavailable

9UIApplicationSignificantTimeChangeNotification重要的时间变化(新的一天开始或时区变化)

10UIApplicationWillChangeStatusBarOrientationNotification-将要改变状态栏方向

11UIApplicationWillChangeStatusBarFrameNotification-将要改变状态栏frame

12UIApplicationWillEnterForegroundNotification

13UIApplicationWillResignActiveNotification

14UIApplicationWillTerminateNotification

 

四、电池、方向、传感器

1UIDeviceBatteryLevelDidChangeNotification//电池电量

2UIDeviceBatteryStateDidChangeNotification//电池状态

3UIDeviceOrientationDidChangeNotification//方向

4UIDeviceProximityStateDidChangeNotification//近距离传感器

 

五、音视频

1MPMediaLibraryDidChangeNotification

2MPMusicPlayerControllerPlaybackStateDidChangeNotification

3MPMusicPlayerControllerNowPlayingItemDidChangeNotification

4MPMusicPlayerControllerVolumeDidChangeNotification

 

六、其他 

1NSUserDefaultsDidChangeNotification用户默认设置变化

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值