gpt4 book ai didi

ios - UIKeyboardWillShowNotification 并在显示键盘时向上滑动

转载 作者:行者123 更新时间:2023-11-28 23:00:26 26 4
gpt4 key购买 nike

这是我的代码:

-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];

CGRect rect = scroll.frame;
if (movedUp)
{
rect.size.height += kOFFSET_FOR_KEYBOARD;
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
}
else
{
rect.size.height -= kOFFSET_FOR_KEYBOARD;
rect.origin.y += kOFFSET_FOR_KEYBOARD;


}
scroll.frame = rect;
[UIView commitAnimations];
}


- (void)keyboardWillHide:(NSNotification *)notif {
[self setViewMovedUp:NO];
}


- (void)keyboardWillShow:(NSNotification *)notif{
[self setViewMovedUp:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:self.view.window];
}

- (void)viewWillDisappear:(BOOL)animated
{
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

问题是,我如何才能将其指定为仅适用于 TextView3,而不适用于 TextView2 或 TextView1。背景是,不需要 TextView1 和 TextView2,因为它们在我的 View 之上。只有TextView3是不可读的TextView,因为键盘被覆盖,必须修正view才能看清我写的内容。

最佳答案

为 textView3 分配一个特殊标签实现 TextView 委托(delegate)方法 - (void)textViewDidBeginEditing:(UITextView *)textView;在这里你将检查 textView 标签是否等于 textView 3 标签调用你的函数 -(void)setViewMovedUp:(BOOL)movedUp .

更多代码:

好的,您需要像这样将 TextViewDelegate 导入到您的 viewController 中:在 .h viewController 文件中 -> viewController : UIViewController<UITextVIewDelegate>

然后在 viewDidload 中为 ex 分配这样的标签:textView3.tag = 222;

然后采用我在“textViewDidBeginEdit”上方编写的委托(delegate)方法,并在内部创建一个 if 语句来检查 textView 标记是否等于 222 调用您的函数。

这是我现在能描述的最好的,因为我是用 iPhone 写的……祝你好运。

关于ios - UIKeyboardWillShowNotification 并在显示键盘时向上滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10109129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com