2
我想實現,當從底部到屏幕頂部滑動時,鍵盤顯示在屏幕上,當在屏幕上從頂部滑動到底部時,鍵盤隱藏。 它就像iOS 7的效果,當我們在屏幕上滑動搜索文本框和鍵盤顯示,當它向下滑動它的隱藏。當在屏幕上滑動時顯示/隱藏鍵盤就像imessenger提供
我想實現,當從底部到屏幕頂部滑動時,鍵盤顯示在屏幕上,當在屏幕上從頂部滑動到底部時,鍵盤隱藏。 它就像iOS 7的效果,當我們在屏幕上滑動搜索文本框和鍵盤顯示,當它向下滑動它的隱藏。當在屏幕上滑動時顯示/隱藏鍵盤就像imessenger提供
試試這個:
//declare a property to store your current responder
@property (nonatomic, assign) id currentResponder;
//in viewDidLoad:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(resignOnSwipe:)];
[self.collectionView addGestureRecognizer:swipe];
//Implement the below delegate method:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
self.currentResponder = textField;
}
//Implement resignOnSwipe:
- (void)resignOnSwipe:(id)sender {
[self.currentResponder resignFirstResponder]
}
嘗試這樣的事情,..它工作正常
在XIB,
添加一個文本框和隱藏。將它連接到.h文件並將其命名爲tf。
在.h文件中,
添加
#import <UIKit/UIKit.h>
@interface KeyboardDisplay : UIViewController <UIGestureRecognizerDelegate>
{
__weak IBOutlet中的UITextField * TF;
}
在.m文件,
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeGesture];
UISwipeGestureRecognizer *swipeGesture2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture2.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture2];
}
-(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender
{
//Gesture detect - swipe up/down , can be recognized direction
if(sender.direction == UISwipeGestureRecognizerDirectionUp)
{
[tf becomeFirstResponder];
NSLog(@"Up");
}
else if(sender.direction == UISwipeGestureRecognizerDirectionDown)
{
[tf resignFirstResponder];
NSLog(@"down");
}
}
注意:不要忘記藏在廈門國際銀行的文本字段。
@Pooja對你有用,.. –