HA ii,我在一个视图tableview和tab中有两个tableview,该选项卡隐藏在主视图下方,用户只能在主视图中看到tableview,用于查看用户必须单击选项卡上方按钮的选项卡,当用户点击按钮时,它会向上移动到主视图,我已使用此代码
完成此操作-(IBAction) controlPanelShowHide:(id)sender
{
CGRect frame = tab.frame;
CGRect viewframe = hideviewoftab.frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.9];
if (!self.isExpanded)
{
self.isExpanded = YES;
if (frame.origin.y -=240) {
tab.frame = frame;
}
if (imageframe.origin.y -=240) {
btnShowHide.frame =imageframe;
}
if (viewframe.origin.y -=240) {
hideviewoftab.frame =viewframe;
}
} else {
self.isExpanded = NO;
if (frame.origin.y +=240) {
tab.frame = frame;
}
if (imageframe.origin.y +=240) {
btnShowHide.frame =imageframe;
}
if (viewframe.origin.y +=240) {
hideviewoftab.frame =viewframe;
}
}
[UIView commitAnimations];
}
使用此代码可以正常工作,但我需要使用触摸事件拖动此选项卡,即。当用户点击并按住它并在屏幕上拖动任何物品时(仅向上)>我认为这是通过- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
来完成的但是我们怎么能这样做呢?抱歉非常糟糕的英语。希望你理解我的问题。
提前致谢。
编辑:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{ CGPoint pt = [[touches anyObject] locationInView:self];
[tab beginAnimations:nil context:nil];
[tab setAnimationDuration:0.1];
CGRect newFrame = tab.frame;
newFrame.origin.y += pt.y - touchingPoint.y;
newFrame.origin.x += pt.x - touchingPoint.x;
[self setFrame:newFrame];
[tab commitAnimations];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint pt = [[touches anyObject] locationInView:self];
[tab beginAnimations:nil context:nil];
[tab setAnimationDuration:0.1];
CGRect newFrame = tab.frame;
newFrame.origin.y += pt.y - touchingPoint.y;
[self setFrame:newFrame];
[tab commitAnimations];
}
答案 0 :(得分:0)
阅读此链接
How can we move a view vertically upward and downwards?
此处使用此代码修改- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
方法
- (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;
newFrame.origin.x += pt.x - touchingPoint.x;
[self setFrame:newFrame];
[UITableView commitAnimations];
}