如何使用Interface Builder设置UIScreenEdgePanGestureRecognizer? [英] How do I set up an UIScreenEdgePanGestureRecognizer using Interface Builder?
问题描述
当我使用Interface Builder将其添加到我的视图控制器时,我无法获得 UIScreenEdgePanGestureRecognizer
工作,所以我在这里要求确定我是否''做错了或者Xcode中有错误。
I can't get UIScreenEdgePanGestureRecognizer
to work when I create when I add it to my view controller using Interface Builder, so I'm asking here to establish whether I'm doing something wrong or if there is a bug in Xcode.
以下是重现的步骤:
- 使用iOS的单一视图应用程序模板创建一个新的Xcode项目。
- 添加
UIView
通过从Interface Builder中的对象库中拖动一个到主视图控制器 - 通过从视图中拖动一个来添加
UIScreenEdgePanGestureRecognizer
到视图Interface Builder中的对象库 - 确保已启用手势识别器并选择了边缘:
- Create a new Xcode project using the "Single View Application" template for iOS.
- Add a
UIView
to the main view controller by dragging one from the Object Library in Interface Builder - Add a
UIScreenEdgePanGestureRecognizer
to the view by dragging one from the Object Library in Interface Builder - Ensure that the gesture recogniser is enabled and that an edge is selected:
- 打开
ViewController
类的助手编辑器,然后按拖动 UIScreenEdgePanGestureRecognizer
到ViewController
的实现块来创建一个新的IBAction
`在动作的方法体中添加断点以测试是否正在识别边缘平移手势
- Open the assistant editor for the
ViewController
class and ctrl-drag from theUIScreenEdgePanGestureRecognizer
to theViewController
's implementation block to create a newIBAction
` Add a breakpoint in the action's method body to test if the edge pan gesture is being recognized
生成的代码如下:
如果我在我的设备上运行该应用程序(运行iOS 8.02的iPhone 6),当我进行边缘滑动时,断点不会被击中。
If I run the application on my device (iPhone 6 running iOS 8.02) the breakpoint does not get hit when I do an edge swipe.
我有什么遗漏吗?
更新:这是作为Apple的错误提交的(rdar:// 18582306)08 -Oct-2014仍未解决Xcode 6.4(6E35b)
推荐答案
我建立了一个项目测试你的问题,发现你遇到了同样的问题。以下是我设置测试的场景:
I set up a project to test your question and found the same issue you did. Here are the scenarios I set up to test:
-
我完全按照您的操作使用Interface Builder构建屏幕边缘的手势。我的代码唯一不同的是我在选择器中放了一行代码,这样调试器就可以停下来了。调试器无法完全停止。
I did exactly as you did, using Interface Builder, to build the screen edge gesture. The only difference in my code is that I put a line of code in the selector so the debugger would have something to stop on. The debugger failed to halt exactly as you found.
-(void)handlePan:(id)sender
{
NSString *test = @"";
}
然后我使用捏手势创建了另一个手势使用Interface Builder查看,我能够让调试器在该选择器中停止。所以Interface Builder似乎能够正确地构建其他手势。
I then created an additional gesture using the pinch gesture on the same view using Interface Builder and I was able to get the debugger to halt within that selector. So Interface Builder seems to be able to build other gestures correctly.
在ViewController.h文件中,我包含了UIGestureRecognizerDelegate。
In the ViewController.h file I included the UIGestureRecognizerDelegate.
@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
@end
在ViewController.m文件中,我手动实现了手势。
In the ViewController.m file I implemented the gesture manually.
#import "ViewController.h"
@interface ViewController ()
-(void)handlePan:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIScreenEdgePanGestureRecognizer *pan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self
action:@selector(handlePan:)];
[pan setEdges:UIRectEdgeLeft];
[pan setDelegate:self];
[self.view addGestureRecognizer:pan];
}
-(void)handlePan:(id)sender
{
NSString *test = @"";
}
@end
我最终得到了同样的结果你做的结论 - Interface Builder的UIScreenEdgePanGestureRecognizer的实现似乎有问题。
I ended up with the same conclusion you did - there seems to be something wrong with the Interface Builder's implementation of the UIScreenEdgePanGestureRecognizer.
这篇关于如何使用Interface Builder设置UIScreenEdgePanGestureRecognizer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!