iphone - 当 Gesture 应用于 self.view 时,我们如何才能使 TableView 工作?

标签 iphone objective-c ios uigesturerecognizer

我已经在整个 View 上应用了手势,我想在 self.view 中与 TableView 进行交互。我已经应用了自定义手势。如下所示:

    #import "TouchEvent.h"
#import <UIKit/UIGestureRecognizerSubclass.h>

@implementation TouchEvent
@synthesize xInc=_inc;
@synthesize prev=_prev;
@synthesize diff=_diff;

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 [self setState:UIGestureRecognizerStateBegan];
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
 [self setState:UIGestureRecognizerStateCancelled];
}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
 UITouch *touch = [touches anyObject];

 // A tap can have slight movement, but we're not interested
 // in a tap. We want more movement. So if a tap is detected
 // fail the recognizer. 

 if ([self state] == UIGestureRecognizerStatePossible) {
  [self setState:UIGestureRecognizerStateBegan];
 } else {
  [self setState:UIGestureRecognizerStateChanged];
 }

 UIView *view = [self view];
 CGPoint touchpoint = [touch locationInView:view];
 CGPoint prevPoint=[touch previousLocationInView:view];


 if (prevPoint.x<touchpoint.x) 
  [self setDiff:(touchpoint.x-prevPoint.x)];
 else
  [self setDiff:(prevPoint.x-touchpoint.x)];

 NSLog(@"difference is: %f",self.diff);
 NSLog(@"x is: %f",touchpoint.x);
 [self setXInc:touchpoint.x];
 [self setPrev:prevPoint.x];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 [self setState:UIGestureRecognizerStateEnded];

}
@end

and I m applying like this

- (void)viewDidLoad
{
 NSArray *ary=[NSArray arrayWithObjects:@"Friends",@"Message",@"Chats",@"New Feeds",@"Photos",@"Notes", nil];
 array=ary;

 gestur=[[TouchEvent alloc] initWithTarget:self action:@selector(SLideTheView:)];

 [self.view addGestureRecognizer:gestur];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}



-(void)moveIt:(CGFloat)x_pos
{
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:0.5];
 [UIView setAnimationDelegate:self];

 [viewU setFrame:CGRectMake(x_pos, 0, 320, 460)];

 [UIView commitAnimations];

}

-(void)SLideTheView:(TouchEvent*)gesture
{

 CGPoint pt=[gesture locationInView:viewU];

      if (pt.x>13&&pt.y>5&&pt.x<29&&pt.y<23) 
      {
       [self slideView];
      }
      else
      {
         if (gesture.state==UIGestureRecognizerStateEnded) 
         {
          if (viewU.frame.origin.x!=0) {
           if (gesture.prev<gesture.xInc) 
           {
            [self moveIt:270];
           }
           else
            [self moveIt:0];
          }
         }
         else
         {
          if (viewU.frame.origin.x!=0) 
          {
           if (gesture.prev<gesture.xInc) 
            x=viewU.frame.origin.x+gesture.diff; 
           else
            x=viewU.frame.origin.x-gesture.diff;

           [viewU setFrame:CGRectMake(x, 0, 320, 460)];
          }
         }

      }

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 label.text=[array objectAtIndex:[indexPath row]];
 [self slideView];
}

运行图像如下:

enter image description here

最佳答案

您可以使用 requireGestureRecognizerToFail: 来在同一 View 上识别两个或多个手势识别器,请参阅示例代码 here

编辑

所以你可以引用这个 one

要引用的方法是- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

引用this question更多

关于iphone - 当 Gesture 应用于 self.view 时,我们如何才能使 TableView 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10381081/

相关文章:

iOS SDK 检测应用程序是否已更新或新安装

iphone - CGFloat 作为属性

ios - 设置包含动态单元格高度的 UITableView 的高度

iphone - 如何在 iPhone 应用程序中显示 Wifi 网络列表?

java - Objective-C 或 iPhone SDK 中是否有相当于 "Focus Listener"的值? (来自 java )

iphone - 再次设置滚动框大小时滚动禁用

ios - 我的 View Controller 和 Storyboard项目周围不需要的蓝色线条

iphone - 如何判断请求何时完成(ASIHTTPRequest)?

objective-c - Objective-C : Uploading and downloading from a server

ios - 在 UITableView 中隐藏/显示单元格?