根据 UIGesture 识别器状态执行操作
这个想法是让进程附加到 UIGestureRecognizer 状态,更具体地说,我想要的是将手势参数记录到可变数组中,当识别手势状态时以及当手势结束时输出可变数组。
最初我以为我可以使用两个 while 循环:
-(void)pincherAction:(UIPinchGestureRecognizer *)sender
{
if ([sender state] == UIGestureRecognizerStateBegan)
{
pinchGesture = YES;
while (pinchGesture)
{
if ([sender state] == UIGestureRecognizerStateEnded)
{
pinchGesture = NO;
} else {
//do array stuff here
}
}
}
if ([sender state] == UIGestureRecognizerStateEnded)
{
pinchGesture = NO;
while (!pinchGesture)
{
if ([sender state] == UIGestureRecognizerStateEnded)
{
pinchGesture = YES;
} else {
//output array here
}
}
}
}
问题是一旦进入 while 循环,它就不会获取任何状态更改。我需要在单独的线程上运行这个循环吗?或者我做了一些根本错误的事情!?
The idea is to have processes attaches to UIGestureRecognizer states more specifically what I want is to record the gesture parameters into a mutable array, when the gesture state is recognized and when the gesture is ended output the mutable array.
Initially I thought I could use two while loops :
-(void)pincherAction:(UIPinchGestureRecognizer *)sender
{
if ([sender state] == UIGestureRecognizerStateBegan)
{
pinchGesture = YES;
while (pinchGesture)
{
if ([sender state] == UIGestureRecognizerStateEnded)
{
pinchGesture = NO;
} else {
//do array stuff here
}
}
}
if ([sender state] == UIGestureRecognizerStateEnded)
{
pinchGesture = NO;
while (!pinchGesture)
{
if ([sender state] == UIGestureRecognizerStateEnded)
{
pinchGesture = YES;
} else {
//output array here
}
}
}
}
The problem is that once in the while loop it doesnt pick up any state changes. Would I need to run this loop on a separate thread? or am I doing something fundamentally wrong!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚使用 UIPinchGestureRecognizer 创建了一个简单的项目。在 viewController 的 awakeFromNib 中设置它:
现在,当我只是进行一些捏合操作并将两个点移动一小段时,会经常调用捏操作方法:
并且会立即识别状态的更改。然而,它只记录您移动手指时的变化。
您不需要 while 循环。
I've just created a simple project with a UIPinchGestureRecognizer. Setting it up in the awakeFromNib for a viewController:
Now, when I just do some pinching and move the two points around for a small around the pinchAction method is called very often:
And a change in state is recognized immediately. However it only records changes when you move around the fingers.
You don't need the while loop.