2014-01-06 70 views

回答

3

試試這個:

//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] 
} 
0

嘗試這樣的事情,..它工作正常

在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"); 
} 
} 

注意:不要忘記藏在廈門國際銀行的文本字段。

+0

@Pooja對你有用,.. –

相關問題