Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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 如何将视图垂直向上和向下移动?_Iphone_Touch - Fatal编程技术网

Iphone 如何将视图垂直向上和向下移动?

Iphone 如何将视图垂直向上和向下移动?,iphone,touch,Iphone,Touch,我的主视图中有一个tableview,我需要用触摸垂直移动这个tableview 我想在触摸任何位置时向上和向下拖动此tableview,当我的手指向上或向下移动时,tableview将根据触摸进行移动 我的主视图中有很多控制器,所以我只想触摸tableview -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; -(void)touchesMoved:(NSSet *)touches withEvent:(UIEve

我的主视图中有一个tableview,我需要用触摸垂直移动这个tableview

我想在触摸任何位置时向上和向下拖动此tableview,当我的手指向上或向下移动时,tableview将根据触摸进行移动

我的主视图中有很多控制器,所以我只想触摸tableview

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
我如何在上述问题中使用这些代表

提前感谢。

-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event
可用于创建表格,点击视图并获取视图的CGPoint,然后使用这些坐标设置tableview框架

注意:-如果使用
-(void)touchsmoved:(NSSet*)touchsevent:(UIEvent*)event使用此功能。

-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)事件可用于创建表格,点击视图并获取视图的CGPoint,然后使用这些坐标设置tableview框架

注意:-如果使用

-(void)touchsmoved:(NSSet*)touchsevent:(UIEvent*)event

您只需创建一个从UITableview继承的类

拖拉

Drag.h应该是这样的

@interface Drag : UITableView { 
    CGPoint touchingPoint;
}
并通过包括以下方法修改Drag.m文件

拖拽

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{ 
    CGPoint pt = [[touches anyObject] locationInView:self];
    touchingPoint = pt;
    [[self superview] bringSubviewToFront:self];    
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event 
{       
    CGPoint pt = [[touches anyObject] locationInView:self];     
    [UITableView beginAnimations:nil context:nil];
    [UITableView setAnimationDuration:0.1];             
    CGRect newFrame = self.frame;
    newFrame.origin.y += pt.y - touchingPoint.y;    
    [self setFrame:newFrame];   
    [UITableView commitAnimations];     
}
就这样

此外,在
viewDidLoad
方法中

把这些线放好

Drag *objDrag = [[Drag alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];

objDrag.delegate = self;
objDrag.dataSource = self;
[objDrag setUserInteractionEnabled:YES];    

[self.view  addSubview:objDrag];

请记住:对于垂直拖动,您必须触摸表的分隔符,否则它将考虑触摸到单元格,将滚动而不是拖动。

< p>您只需生成一个类,继承自UITababVIEW

拖拉

Drag.h应该是这样的

@interface Drag : UITableView { 
    CGPoint touchingPoint;
}
并通过包括以下方法修改Drag.m文件

拖拽

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{ 
    CGPoint pt = [[touches anyObject] locationInView:self];
    touchingPoint = pt;
    [[self superview] bringSubviewToFront:self];    
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event 
{       
    CGPoint pt = [[touches anyObject] locationInView:self];     
    [UITableView beginAnimations:nil context:nil];
    [UITableView setAnimationDuration:0.1];             
    CGRect newFrame = self.frame;
    newFrame.origin.y += pt.y - touchingPoint.y;    
    [self setFrame:newFrame];   
    [UITableView commitAnimations];     
}
就这样

此外,在
viewDidLoad
方法中

把这些线放好

Drag *objDrag = [[Drag alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];

objDrag.delegate = self;
objDrag.dataSource = self;
[objDrag setUserInteractionEnabled:YES];    

[self.view  addSubview:objDrag];

记住:用于垂直拖动,你必须触摸表的分隔符,否则它会考虑触摸到单元格并滚动而不是拖动。

我想一点点Google会给你更快的答案。我想一点点Google会给你更快的答案,但是如何设置TabVIEW X和Y轴符合触摸点开始触摸事件的要点。并将其用作表视图的框架。mytableView=[[UITableView alloc]initwithframe:CGRectMake(点x、点y、宽度、高度)];flow sequence touchevent-->[self drawTable:point]-->inside方法设置表格的框架,但如何设置表格视图x和y轴以进行触摸从触摸开始的触摸事件获取点,并将其用作表格视图的框架。mytableView=[[UITableView alloc]initwithframe:CGRectMake(点x、点y、宽度、高度)];flow sequence touchevent-->[self drawTable:point]-->inside方法设置表格的框架是自动移动还是按fingure移动。如果你想让它通过fingure移动,它被称为drag,这里drag只是类的名称,如果你觉得它不适合你的编码参考,你可以改变它,你想让它自动移动还是通过fingure移动。如果您希望它通过fingure移动,它被称为drag,这里drag只不过是类的名称,如果您发现它不适合您的编码参考,您可以更改它