系统通知

来源:互联网 发布:qq炫舞淘宝买对戒 编辑:程序博客网 时间:2024/04/28 23:27

标签: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"

@interfaceViewController ()

{

    UITextField *tempTF;

}

@property (weak,nonatomic) IBOutletUITextField *tf1;

@property (weak,nonatomic) IBOutletUITextField *tf2;

@property (weak,nonatomic) IBOutletUITextField *tf3;

@property (weak,nonatomic) IBOutletUITextField *tf4;

 

@property (weak,nonatomic) IBOutletUITextField *tf5;

@end

@implementation ViewController

- (void)viewDidLoad {

    [superviewDidLoad];

   //注册viewController为监听者,并向通知中心发送信息

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardShow:)name:UIKeyboardWillShowNotificationobject:nil];

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardHidden:)name:UIKeyboardWillHideNotificationobject: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= [rectCGRectValue].size.height;

//获取屏幕尺寸    

CGFloat screen_height= [[UIScreenmainScreen]bounds].size.height;

    CGFloat screen_width = [[UIScreenmainScreen]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 = [[UIScreenmainScreen]bounds].size.height;

    CGFloatscreen_width = [[UIScreenmainScreen]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;

    returnYES;

}

//按return键盘消失

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    return [textFieldresignFirstResponder];

}

- (void)didReceiveMemoryWarning{

    [superdidReceiveMemoryWarning];

}

@end



0 0
原创粉丝点击