框架类的 键盘监控 消退
来源:互联网 发布:raphael js api 编辑:程序博客网 时间:2024/04/29 04:25
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];
// register for keyboard notifications
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(keyboardWillShow:)
name
:
UIKeyboardWillShowNotification
object
:
self
.view
.window
];
// register for keyboard notifications
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(keyboardWillHide:)
name
:
UIKeyboardWillHideNotification
object
:
self
.view
.window
];
keyboardIsShown =
NO
;
//make contentSize bigger than your scrollSize
//(you will need to figure out for your own use case)
CGSize
scrollContentSize = CGSizeMake(
3
2
0
,
3
4
5
);
self
.scrollView
.contentSize
= scrollContentSize;
}
- (
void
)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
// unregister for keyboard notifications while not visible.
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIKeyboardWillShowNotification
object
:nil
];
// unregister for keyboard notifications while not visible.
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIKeyboardWillHideNotification
object
:nil
];
}
- (
void
)dealloc {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
// unregister for keyboard notifications while not visible.
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIKeyboardWillShowNotification
object
:nil
];
// unregister for keyboard notifications while not visible.
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:UIKeyboardWillHideNotification
object
:nil
];
}
- (
void
)keyboardWillHide:(
NSNotification
*)n
{
NSDictionary* userInfo = [n
userInfo
];
// get the size of the keyboard
CGSize
keyboardSize =
[[userInfo
objectForKey
:UIKeyboardFrameBeginUserInfoKey]
CGRectValue
]
.size
;
// resize the scrollview
CGRect
viewFrame =
self
.scrollView
.frame
;
// I'm also subtracting a constant kTabBarHeight because my UIScrollView
// was offset by the UITabBar so really only the portion of the keyboard that
// is leftover pass the UITabBar is obscuring my UIScrollView.
viewFrame
.size
.height
+= (keyboardSize
.height
- kTabBarHeight);
[
UIView
beginAnimations
:nil
context
:
NULL
];
[
UIView
setAnimationBeginsFromCurrentState
:
YES
];
// The kKeyboardAnimationDuration I am using is 0.3
[
UIView
setAnimationDuration
:kKeyboardAnimationDuration];
[
self
.scrollView
setFrame
:viewFrame];
[
UIView
commitAnimations
];
keyboardIsShown =
NO
;
}
- (
void
)keyboardWillShow:(
NSNotification
*)n
{
// This is an ivar I'm using to ensure that we do not do the frame size
// adjustment on the UIScrollView if the keyboard is already shown.
// This can happen if the user, after fixing editing a UITextField,
// scrolls the resized UIScrollView to another UITextField and attempts
// to edit the next UITextField. If we were to resize the UIScrollView again,
// it would be disastrous. NOTE: The keyboard notification will fire
// even when the keyboard is already shown.
if
(keyboardIsShown) {
return
;
}
NSDictionary* userInfo = [n
userInfo
];
// get the size of the keyboard
CGSize
keyboardSize =
[[userInfo
objectForKey
:UIKeyboardFrameBeginUserInfoKey]
CGRectValue
]
.size
;
// resize the noteView
CGRect
viewFrame =
self
.scrollView
.frame
;
// I'm also subtracting a constant kTabBarHeight because my UIScrollView
// was offset by the UITabBar so really only the portion of the keyboard
// that is leftover pass the UITabBar is obscuring my UIScrollView.
viewFrame
.size
.height
-= (keyboardSize
.height
- kTabBarHeight);
[
UIView
beginAnimations
:nil
context
:
NULL
];
[
UIView
setAnimationBeginsFromCurrentState
:
YES
];
// The kKeyboardAnimationDuration I am using is 0.3
[
UIView
setAnimationDuration
:kKeyboardAnimationDuration];
[
self
.scrollView
setFrame
:viewFrame];
[
UIView
commitAnimations
];
keyboardIsShown =
YES
;
}
Tag : keyboard , UIScrollView , 键盘
- 框架类的 键盘监控 消退
- iOS 让scrollView 上面的textField消退键盘
- iOS 在tableView上消退键盘
- iOS 在tableView或scrollView上,消退键盘
- 复杂页面消退的一个简单实例
- 管理键盘的框架
- 键盘监控
- iOS键盘监控键盘
- WINDOWS键盘事件的挂钩监控原理
- [Delphi]Delphi监控键盘鼠标的程序
- Android系统上的键盘监控
- 【Android】系统上的键盘监控
- 多级模态窗口的解散消退问题 presentModalViewController
- 陈彤出走,小米生态梦的消退
- 监控键盘鼠标
- SDL 键盘事件监控
- 实现键盘监控
- 键盘监控分析
- 禁止某几个文件用ARC模式编译
- 改了n遍后的结果~~
- 四川渠县政府将小学操场拍卖出售 学生错峰放学-四川-操场-拍卖
- 消息耦合还是接口耦合
- Linux2.6 DM9000驱动模编译为模块
- 框架类的 键盘监控 消退
- uml 简介
- 乔布斯为什么要用Objective-C作为iOS平台编程语言?
- 配置putty登陆ubuntu
- UML-----关系
- 朴素模式匹配
- Chrome的Content Scripts扩展开发
- 0.ring3-反调试小结
- [嵌入式开发]Windows CE 之BSP开发浅谈