gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:52 33 4
gpt4 key购买 nike

我已经在整个 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/

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