惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
MyScale Blog
MyScale Blog
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
Recent Announcements
Recent Announcements
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 狗尾草-大数据收割基

微信小程序-本地云函数调试失败,卡在“正在开启本地调试中” VS Code调试Python时,选择conda虚拟环境,配置环境变量 微信小程序集成vant mac配置ssh 到github (ios)MPMoviePlayerController首次播放视频的时候,没有控制条 ios app响应background,foreground 事件实现 ios UIScrollView 中控件自动增加间隔 iOS 导航栏实现总结 ios界面布局整理 android ProGuard 代码混淆实现 mac版 android破解软件下载安装 在unix系统下的 .o文件 .a文件 .so文件说明和相互关系 android中的广播接收实现总结 用java的jdk 生成android 的jni接口文档 Android 自定义Application android项目中配置NDK自动编译生成so文件 创建android Notification (ios) 屏幕触摸总结 sqlite数据库 select 查询带换行符数据
(ios) nsnotification总结
狗尾草-大数据收割基 · 2014-01-20 · via 博客园 - 狗尾草-大数据收割基

1  文本输入,键盘显示时,view向上,键盘隐藏时,view向下

1.1 注册键盘显示,关闭通知,并实现主界面上下变动

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}


-(void)keyboardWillShow:(NSNotification *)aNotification
{

    CGRect keyBoardRect=[[[aNotification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue];
    
    NSTimeInterval animalInterval=[[[aNotification userInfo]objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect frame=self.view.frame;
    frame.origin.y=-keyBoardRect.size.height;
    [UIView beginAnimations:@"keyboardshow" context:nil];
    [UIView setAnimationDuration:animalInterval];
    self.view.frame=frame;
    [UIView commitAnimations];


}

-(void)keyboardWillHide:(NSNotification *)aNotification
{

    NSTimeInterval animalInterval=[[[aNotification userInfo]objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect frame=self.view.frame;
    frame.origin.y=0;
    [UIView beginAnimations:@"keyboardhide" context:nil];
    [UIView setAnimationDuration:animalInterval];
    self.view.frame=frame;
    [UIView commitAnimations];
    
}

1.2 文本框初始化,并实现UITextViewDelegate委托

    self.textbox.returnKeyType=UIReturnKeyDone;
    self.textbox.delegate=self;
}

 - (BOOL)textFieldShouldReturn:(UITextView *)textView
{
 [textView resignFirstResponder];
    return YES;
}

2 自定义notification

 2.1 定义侦听自定义notification观察者

//注册观察者,侦听自定义通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selfNotificationDO:) name:@"CustomNotification" object:nil];

}

-(void)selfNotificationDO:(NSNotification *)aNotification
{
     //处理notification
    //........
}

2.2 生成一个自定义notification

//生成一个自定义Notification
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CustomNotification" object:self];