IOS学习之——通知中心NSNotificationCenter

//*****************************************************************************     -8通知中心
//-键盘位置改变的通知
            //项目名称:QQ
            //点击Text Field 文本框会回到键盘的上方   就可以显示自己输入的信息。
            //   注意点  :这个textfield 中 小view 中

            //键盘的通知
            //UIKeyboardWillShowNotification (键盘即将显示)
            //UIKeyboardDidShowNotification (键盘已经显示)
            //UIKeyboardWillHideNotification (键盘即将隐藏)
            //UIKeyboardDidHideNotification(键盘已经隐藏)
            //UIKeyboardWillChangeFrameNotification(键盘的尺寸即将发生改变)
            //UIKeyboardDidChangeFrameNotification (键盘的尺寸已经发生改变)

            //        UIKeyboardAnimationCurveUserInfoKey = 7;
            //        UIKeyboardAnimationDurationUserInfoKey = "0.25"; 动画持续的时间
            //        UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}";键盘的大小
            //        UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 796}"; 中心点的坐标
            //        UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}";结束动画中心点的坐标
            //        UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 667}, {375, 258}}";
            //        UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 409}, {375, 258}}";结束以后你的位置和大小
            //    }


            - (void)viewDidLoad {
                [super viewDidLoad];
                //订阅通知
//                addObserver 订阅者    name 通知的名称   object  谁发的通知 (selector) 方法
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
            }
            //键盘的位置或大小发生改变
            - (void)keyboardWillChangeFrame:(NSNotification *)noti
            {
                CGFloat duration = [noti.userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
                CGRect frame = [noti.userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
                CGFloat offsetY = frame.origin.y - self.view.frame.size.height;

                [UIView animateWithDuration:duration animations:^{
                    self.view.transform = CGAffineTransformMakeTranslation(0, offsetY);
                }];
             -(void)dealloc
                {
                    //退订
                    [[NSNotificationCenter defaultCenter] removeObserver :self ];

                }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值