【问题标题】:button should fire the action until I keep the button down按钮应该触发动作,直到我按住按钮
【发布时间】:2011-10-01 10:39:02
【问题描述】:
我有 UIscrollview 我在其中放置了图像。我使用按钮(向下触摸)在滚动视图内将图像的位置移动 5 个像素......只有当我反复触摸按钮时按钮才会触发操作(它如果我一次又一次地触摸按钮,将图像移动到 5 像素)我希望我的按钮触发动作,直到我按住按钮(它应该移动图像直到我释放按钮)......
是否有可能通过单击按钮来滚动 UIscrollview?
【问题讨论】:
标签:
iphone
uiscrollview
uibutton
【解决方案1】:
您必须监听 TouchDown 和 TouchUp 事件。当触发 TouchDown 事件时,您将启动一个定期调用方法的计时器(或其他),并在收到 TouchUp 事件时停止它。
它可能看起来像这样:
-(IBAction)touchDownAction:(id)sender
{
self.yourtimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(aselector) userInfo:nil repeats:YES];
}
-(IBAction)touchUpAction:(id)sender
{
if ([yourtimer isValid])
{
[yourtimer invalidate];
}
}
(您只需通过 IB 将您的按钮与这些方法链接)