3

我有一些 UIView,我希望用户能够在屏幕上“轻弹”。它们不是滚动视图。它们只包含一个光栅图像 (png)。任何人都可以指出一些示例代码等来帮助我入门吗?比“MoveMe”更重量级的东西可以帮助检测“轻弹”(相对于“轻推”或拖放),然后将视图移向“轻弹”的方向?

OpenGL 可能矫枉过正。如果可能的话,我想留在核心图形/动画领域。

4

6 回答 6

2

我想说实现这一点的最简单的方法是将您的视图放入启用分页的 UIScrollView 容器中,并让它担心所有“轻弹”操作。对我很有用。

您甚至可以通过一些额外的努力让视图延迟加载图像。

于 2009-06-28T10:37:21.097 回答
1

我想您可以通过获取 nazgul42 答案并检查两个提到的事件之间的时间来轻松实现这一点。短时间和长距离的结合可以被解释为轻弹。您还可以通过计算两个触摸事件点的坐标来确定轻弹的方向。

于 2009-08-03T14:53:35.520 回答
0

假设你有一个UIView被叫aView和两个UIImageViewspage1page2。假设您已经page1在 中作为子视图aView,则此代码将从 翻转page1page2

[UIView beginAnimations:@"someId" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:aView cahe:YES];
[page1 removeFromSuperview];
[aView addSubview:page2];
[UIView commitAnimations];
于 2009-06-25T18:14:16.997 回答
0

要检测触摸,在视图控制器中,您可以使用 touchesBegan 和 touchesEnded 方法,从 touchesBegan 存储触摸,如果触摸向左或向右移动超过一定量,则它是轻弹,而不是轻推左还是右。

于 2009-06-25T21:22:28.597 回答
0

我在这里找到了一个线程,尽管该方法让我担心-

http://discussions.apple.com/message.jspa?messageID=7862186

它不考虑速度或时间戳;只是自上次事件更新以来的距离。如果 Apple 更改了事件更新的频率/粒度,则此代码可能会损坏。

于 2010-03-12T23:10:38.827 回答
0

尝试使用UIPanGentureRecognizer示例代码:

UIPanGestureRecognizer *imageGesture = [[UIPanGestureRecognizer alloc]
                                         initWithTarget:self
                                         action:@selector(imageDragged:)];
[imageView1 addGestureRecognizer:imageGesture];

然后

- (void)imageDragged:(UIPanGestureRecognizer *)gesture{
UIImageView *imageView = (UIImageView *)gesture.view;
CGPoint translation = [gesture translationInView:imageView];

imageView.center = CGPointMake(imageView.center.x + translation.x,
                               imageView.center.y + translation.y);
imageView2.center = imageView.center;
imageView3.center = imageView.center;

[gesture setTranslation:CGPointZero inView:imageView];}
于 2015-10-30T07:37:53.217 回答