- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在我的 iPhone 应用程序中处理旋转手势并在此期间旋转 imageView。在手势结束时,我想将 imageView 旋转到固定位置。所以,即。如果我将 imageView 从 0 弧度旋转到 M_PI/2 弧度,但在中途的某个地方我以手势结束。结束后我想测试角度,如果它接近 M_PI/2,则将其设置为 M_PI/2,否则设置为 0。
这是我尝试执行此操作的代码:
我创建识别器并将其添加到我的 View 中。
UIGestureRecognizer *recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRecognized:)];
recognizer.delegate = self;
[self addGestureRecognizer:recognizer];
[recognizer release];
委托(delegate)方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (_imageView) {
trả về CÓ;
}
trả về KHÔNG;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
trả về CÓ;
}
手势识别方法:
- (void)gestureRecognized:(UIRotationGestureRecognizer *)recognizer {
_imageView.transform = CGAffineTransformMakeRotation(recognizer.rotation);
}
这些方法都有效,但这是我尝试结束手势的方法。这不起作用:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"gesture end");
}
还有一个关于转换的小问题。有时会回到 0 弧度。
欢迎任何建议。谢谢!
câu trả lời hay nhất
我在其他论坛上找到了答案。我希望这也会对其他人有所帮助。答:
You can detect the end of the gesture by checking the UIRotationGestureRecognizer's state in your action method. If [gestureRecognizer state] == UIGestureRecognizerStateEnded then it's done. If something had instead caused it to be cancelled (for instance, a phone call coming in) then you'd see it end in UIGestureRecognizerStateCancelled instead.
If you want to apply the recognizer's rotation directly to your view rather than treat it as a delta from the previous location you can set the recognizer's rotation the its state is UIGestureRecognizerStateBegan, and then it will calculate offsets from that value and you can apply them directly. This just requires that you remember the rotation you last ended at, and then you can do something like [gestureRecognizer setRotation:lastAppliedRotation] when the recognizer's state is UIGestureRecognizerStateBegan.
关于iphone - UIGestureRecognizer 结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4951617/
我知道触摸事件可以传递给点击 View 或手势。但在我的演示中有些让我感到困惑: 我的 Root View 中有两个 subview ,一个是 testView(UIView 的子类),另一个是 te
我有一个带有一些手势识别器(ala Clear)的 View 。我应该只为语音用户添加按钮吗? 我考虑过使用提示来表达类似“3 指向右滑动以编辑。向左滑动以删除。向上滑动以创建新的”之类的内容。但似乎
我有两个问题: 我能否实现继承自 UISwipeGestureRecognizer 的手势识别器并将逻辑添加到 UIEvent 处理程序? 我可以在不将它附加到 UIView 的情况下实现 UIGes
我正在开发 iPhone 应用程序,但遇到了手势识别器的问题。 我在一个 View 上添加了一个 UITapGestureRecognizer,然后我用 CABasicAnimation 转换与这个
我有很多类,想要将 UIGestureRecognizer 添加到它们的 UIImageViews 中。 我正确地将一个添加到所有类中。问题是我重复了代码,以便每个类都添加相同的识别器。这些是本地识别
我想在我的 UIPinchGestureRecognizer 完成捏合手势时收到回调。此外,如果知道完成的手势是放大还是缩小,那就太好了。 有人知道使用方法吗?或者采取什么方法? 谢谢! 最佳答案 另
我已经在 View Controller 的 viewDidLoad 上设置了 UITapGestureRecognizer,但不知何故,它会为单次点击触发两次选择器方法。 UITapGestureR
我正在使用 UIPanGestureRecognizer在几个类似卡片的 View 上,让用户在屏幕上移动 View 。他们可以同时放下 3 个手指并拾取 3 张卡片,这非常好,但是,我的某些功能并不
这里给出一个例子,(使用 ARC ) UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init
当我使用 UIGestureRecognizer ,例如,当用户向右滑动时,我想要一个 UIAlertView询问他是否真的要进行向右滑动的 Action 。 我曾尝试这样做,但没有成功。 最佳答案
我有一个子类 UIView ,我们称之为TileView.m/h . 在 TileView.m ,我有以下代码:( [setup] 肯定被调用,我用断点检查过)。 - (void)setup {
我有一个 UIGestureRecognizer附加到 UILabel当稍后进入视野时,它会在屏幕外渲染。进入视野后,点击手势识别器不起作用。如果在 View 中渲染,它工作正常。 任何想法为什么这不
我已经使用 UIPanGestureRecognizer 实现了一些交互式 UIViewController 演示动画,例如平移以呈现 View Controller 。 我现在要做的是允许这种行为通
在我的 tvOS 应用程序中,我有一个 Collection View ,其中包含代表电影的单元格。 我在 View 上附加了 2 个手势识别器: 点击选择即可查看电影详细信息 直接播放影片(使用 A
UIGestureRecognizer 导致未捕获的异常错误。它说无法识别的选择器发送到实例。我正在使用 Swift 3 和 Xcode 8。 这是代码。 import UIKit import UI
我正在制作一个在图像上包含几个图层的应用程序。该效果层是 UIView - EffectsLayerView 的子级。里面有Effect1View、Effect2View和Effect3View,其中
我有两个类,它们都添加了 UIPinchGestureRecognizer 并使用选择器来处理响应手势的代码。注意:手势识别器委托(delegate)可能与此问题无关,但我将其包含在代码中,以防万一。
我正在尝试学习 Swift,这让我很困惑: 假设您要添加手势: faceView.addGestureRecognizer(UIPinchGestureRecognizer(targe
我刚开始使用适用于 iOS 的 Google Maps SDK,但遇到了一些问题。我正在尝试添加以下代码: - (void)viewDidLoad { [super viewDidLoad];
我正在学习 iOS 开发并且正在查看 UIGestureRecognizer 的。 我有一个观点。当您点击该 View 时,我想显示一个 UIPopoverController 并且我还希望它像 UI
Tôi là một lập trình viên xuất sắc, rất giỏi!