iPhone上的TouchEvent疑点 [英] TouchEvent doubts in iphone
问题描述
HA ii,i在一个视图中有两个tableview tableview和tab,该tab隐藏在mainview下方,用户只能在mainview中看到tableview,要查看此tab,用户必须单击tab上方的按钮,当用户点击按钮时,它向上拖动到主视图,我已经通过使用以下代码完成了此操作
HA ii ,i have two tableview in one view tableview and tab,the tab is hidden below the mainview,the user can see only tableview in the mainview,for viewing the tab the user have to click button just above the tab,when the user tap the button it drage upwards to the mainview i have done this by using this code
-(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
但是我们该怎么办?对不起,英语很不好.希望您能理解我的问题.提前致谢.
every things work fine with this code,but i need to drag this tab with touch event ,i.e. when the user tap and hold it and drag any-ware on the screen (upwards only)> i think this is done through - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
But how can we done this ?sorry for the very very poor english.Hope you understand my question.
thanks in advance.
- (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];
}
推荐答案
阅读此链接
此处使用此代码修改-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
方法
Here modify the - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
method with this code
- (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];
}
这篇关于iPhone上的TouchEvent疑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!