监听键盘的出现和隐藏顶部View值得改变

- (UITextView *)publishTextView

{

if (!_publishTextView)

{

UITextView *publishTextView = [[UITextView alloc] init];

publishTextView.font = ContentTitleFont;

publishTextView.frame = CGRectMake(0, 0, Screen_Width, Screen_Height);

// 键盘成为第一响应者

[publishTextView becomeFirstResponder];

self.publishTextView = publishTextView;

[self.view addSubview:publishTextView];

}

return _publishTextView;

}

- (YSWeiBoPublishToolbar *)publishToolbar

{

if (!_publishToolbar)

{

YSWeiBoPublishToolbar *publishToolbar = [[YSWeiBoPublishToolbar alloc] init];

CGFloat publishToolbarHeight = 44.f;

publishToolbar.frame = CGRectMake(0, Screen_Height - publishToolbarHeight, Screen_Width, publishToolbarHeight);

self.publishToolbar = publishToolbar;

[self.view addSubview:publishToolbar];

}

return _publishToolbar;

}

- (void)viewDidLoad

{

[super viewDidLoad];

self.publishTextView.delegate = self;

self.publishToolbar;

[self setupNavigationItem];

[YSWeiBoNotificationCenter addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

}

#pragma mark - 监听方法

/** */

- (void)keyboardWillChangeFrame:(NSNotification *)notification

{

NSDictionary *userInfo = notification.userInfo;

// 动画的持续时间

double duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

// 键盘的frame

CGRect keyboardF = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

[UIView animateWithDuration:duration animations:^{

if (keyboardF.origin.y > self.view.height) { // 键盘的Y值已经远远超过了控制器view的高度

self.publishToolbar.y = self.view.height - self.publishToolbar.height;

} else {

self.publishToolbar.y = keyboardF.origin.y - self.publishToolbar.height;

}

}];

}

时间: 2024-07-30 13:43:52

监听键盘的出现和隐藏顶部View值得改变的相关文章

2016-02-22 监听键盘 隐藏bar

- (BOOL)prefersStatusBarHidden{ return YES; }   //隐藏bar 2:让键盘消失 ////    [_lastField resignFirstResponder]; //    [self.view endEditing:YES];//gzz0223 // //    //gzz0223 键盘消失 //    NSArray *subviews = [self.view subviews]; //    for (id objInput in su

避免scrollview内部控件输入时被键盘遮挡,监听键盘弹起,配合做滚动

1,监听键盘 2,根据当前键盘弹起高度与控件的底部位置计算滑动距离 3,根据滑动距离在键盘弹起和隐藏是分别设置动画完成滑动 实现: 1,监听键盘使用 #pragma mark - 键盘监听-(void)AddObserverForKeyboard{    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillShow:) name:UIKeyboardWillShow

IOS 监听键盘的通知

通知方法: /** * 当键盘改变了frame(位置和尺寸)的时候调用 */ - (void)keyboardWillChangeFrame:(NSNotification *)note { // 设置窗口的颜色 self.view.window.backgroundColor = self.tableView.backgroundColor; // 0.取出键盘动画的时间 CGFloat duration = [note.userInfo[UIKeyboardAnimationDuration

iOS 监听键盘高度,输入框上升

1 //设置输入框 ---<因为输入框用了get方法,所以第一次调用输入框要用self 调用>: 2 self.textlab.frame=CGRectMake(20, 420, 250, 30); 3 _textlab.layer.borderColor=[UIColor blueColor].CGColor; 4 _textlab.layer.borderWidth= 0.5f; 5 _textlab.backgroundColor=[UIColor colorWithRed:0.830

通过KVO来监听键盘弹出和弹回

在通知中心建立一个广播来监听键盘的弹出和弹回,在监听事件中加入触发事件的一些操作. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self sele

Android 监听键盘弹出和收起.

entends:http://stackoverflow.com/questions/36837066/how-to-validate-virtual-keyboard-visibility 监听键盘弹出和收起. /* Somewhere else in your code */ RelativeLayout mainLayout = findViewById(R.layout.main_layout); // You must use your root layout InputMethodM

监听键盘事件

注册监听键盘事件: 1 // 键盘即将隐藏 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 3 4 // 键盘已经隐藏 5 [[NSNotificationCenter defaultCenter] addObserver:self selector:@sel

21-30(NSTimer定时器 Cell的重用原理 代理的使用场合 UITableViewCell结构 监听键盘的通知)

21.NSTimer定时器 22.tableView的基本用法 23.tableView的常用属性 24.Cell的重用原理: 25.UITableViewCell结构 26.使用xib封装一个view的步骤 27.代理的使用场合 28.使用delegate的步骤 29.通过代码自定义cell步骤 30.监听键盘的通知 { 细节决定成败, 这句话讲的太对了, 所以我们要注意每一个细节!今天还好注意了, 没犯错!嘿嘿! 今天心情特别好, 心情好! 啥都好! 给大家来个笑, 工作的同时,不要忘记笑容

swift 监听键盘弹出的高度

// 监听键盘通知 NotificationCenter.default.addObserver(self, selector: #selector(ComposeViewController.keyboardWillChangeFrame(note:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil) //监听键盘的事件 func keyboardWillChangeFrame(note: Notificat