简体   繁体   English

在iPhone的SDK上的UITableView检测触摸

[英]Detecting touches on UITableView in iphone sdk

我想在用户按下单元格的按钮时对图像进行动画处理,我在每个单元格的末尾创建了按钮,当用户按下按钮时, 图像动画从该按钮开始,我该怎么办?,我使用了触摸开始功能,但在tableview上不起作用.....我想在tableview单元格的按钮上获得x,y的触摸位置。

您可以使用didSelectRowAtIndexPath:

if you are using button then you can addTarget to that button and do the task in the method registered for that button.Whats the need of using touches began if you are using button? 如果您使用的是按钮,则可以将Target添加到该按钮,并以该按钮注册的方法执行任务。如果您使用的是按钮,则需要使用触摸吗? For getting x and y you already have the xy position of the button, use that 为了获得x和y,您已经具有按钮的xy位置,请使用

Try calling the animation in different Thread. 尝试在其他线程中调用动画。

[NSThread detachNewThreadSelector:@selector(startAnimating) toTarget:self withObject:nil];

I think you can add target to each button when you are creating cells means in cellForRowAtIndexPath and you can get x and y for that buttton when pressed in that action- 我认为您可以在cellForRowAtIndexPath中创建单元时在每个按钮上添加目标,并且在该操作中按下该按钮时可以获取该按钮的x和y-

(UIButton*)sender.frame.origion.x (UIButton *)sender.frame.origion.x

and

(UIButton*)sender.frame.origion.y (UIButton *)sender.frame.origion.y

            NSSet *touches = [event allTouches];

        UITouch *touch = [touches anyObject];

        CGPoint currentTouchPosition = [touch locationInView:self.view];

        CGPoint xLocation;

        xLocation = CGPointMake(currentTouchPosition.x-35,currentTouchPosition.y-10);

        pressPoint = xLocation;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM