Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 当手势应用于self.view时,我们如何使表视图工作?_Iphone_Objective C_Ios_Uigesturerecognizer - Fatal编程技术网

Iphone 当手势应用于self.view时,我们如何使表视图工作?

Iphone 当手势应用于self.view时,我们如何使表视图工作?,iphone,objective-c,ios,uigesturerecognizer,Iphone,Objective C,Ios,Uigesturerecognizer,我已经在整个视图上应用了手势,我想在self.view中与表视图交互。我已经应用了自定义手势。如下所示: #import "TouchEvent.h" #import <UIKit/UIGestureRecognizerSubclass.h> @implementation TouchEvent @synthesize xInc=_inc; @synthesize prev=_prev; @synthesize diff=_diff; -(void)touchesBega

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

    #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
#导入“TouchEvent.h”
#进口
@实现触摸事件
@综合新科股份有限公司;
@综合预测=_预测;
@合成diff=_diff;
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
[自设置状态:UIgestureRecognitizerStateStarted];
}
-(无效)触控取消:(NSSet*)触控事件:(UIEvent*)事件
{
[自设置状态:UIgestureRecognizerStateConcelled];
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
//水龙头可以有轻微的移动,但我们不感兴趣
//在点击中。我们需要更多的移动。所以如果检测到点击
//使识别器失败。
如果([self state]==UIgestureRecognitzerState可能){
[自设置状态:UIgestureRecognitizerStateStarted];
}否则{
[自设置状态:UIgestureRecognitizerStateChanged];
}
UIView*视图=[自视图];
CGPoint touchpoint=[触摸位置视图:视图];
CGPoint prevPoint=[触摸previousLocationInView:视图];

如果(prevPoint.x13&&pt.y>5&&pt.x,您可以使用
RequireTestureRecognitizerToFail:
在同一视图上识别两个或多个手势识别器,请参见示例代码

编辑

因此,您可以参考此

要引用的方法是
-(BOOL)手势识别器:(UIGestureRecognizer*)手势识别器应接收touch:(UITouch*)touch


请参阅更多信息

谢谢您的回复,但我不想在一个视图上识别多个手势。我只想在主视图和我的表视图(即子视图)上应用手势。感谢您关注我的问题,但这不符合我的要求。请运行我的代码,您将更好地理解我的问题。我希望将我的应用程序保持原样,但tableview也应配合使用。你可以给我你的电子邮件id,我将在其上发送应用程序。然后你将能够运行。
- (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];
}
//add gesture to mapview-for single touch
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SLideTheView:)];
[self.view addGestureRecognizer:tap];
tap.numberOfTapsRequired = 1;


//add another gesture to terminate first one
UITapGestureRecognizer *secondGest= [[UITapGestureRecognizer alloc] init];
[tableview addGestureRecognizer:secondGest]; 
[tap requireGestureRecognizerToFail:secondGest];
[secondGest release];
[tap release];