ios - 如何使用 Interface Builder 设置 UIScreenEdgePanGestureRecognizer?

标签 ios objective-c xcode interface-builder

当我使用 Interface Builder 将它添加到我的 View Controller 时,我无法让 UIScreenEdgePanGestureRecognizer 工作,所以我在这里问我是否做错了什么或者是否Xcode 中存在错误。

重现步骤如下:

  • 使用适用于 iOS 的“单 View 应用程序”模板创建一个新的 Xcode 项目。
  • 从 Interface Builder 的对象库中拖出一个 UIView 到主视图 Controller
  • 通过从 Interface Builder 的对象库中拖动一个 UIScreenEdgePanGestureRecognizer 到 View
  • 确保已启用手势识别器并选择了一条边:

enter image description here

  • 打开 ViewController 类的辅助编辑器,按住 ctrl 从 UIScreenEdgePanGestureRecognizer 拖动到 ViewController 的实现 block 以创建一个新的IBAction ` 在 Action 的方法体中添加一个断点以测试是否正在识别边缘平移手势

结果代码如下:

Code example

如果我在我的设备(运行 iOS 8.02 的 iPhone 6)上运行该应用程序,则当我进行边缘滑动时断点不会命中。

有什么我想念的吗?

更新:这是 Apple (rdar://18582306) 于 2014 年 10 月 8 日提交的错误,在 Xcode 6.4 (6E35b) 中仍未解决

最佳答案

我建立了一个项目来测试你的问题,发现了你遇到的同样问题。以下是我设置的测试场景:

  • 我完全按照您的方式使用 Interface Builder 来构建屏幕边缘手势。我的代码中唯一的区别是我在选择器中放了一行代码,这样调试器就会停止。调试器未能完全按照您的发现停止。

    -(void)handlePan:(id)sender
    {
        NSString *test = @"";
    }
    
  • 然后,我使用 Interface Builder 在同一 View 上使用捏合手势创建了一个额外的手势,我能够让调试器在该选择器内停止。因此 Interface Builder 似乎能够正确构建其他手势。

  • 然后我使用以下代码手动创建了屏幕边缘手势,它按预期工作。

在 ViewController.h 文件中,我包含了 UIGestureRecognizerDelegate。

@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
@end

在 ViewController.m 文件中,我手动实现了手势。

#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 的实现似乎有问题。

关于ios - 如何使用 Interface Builder 设置 UIScreenEdgePanGestureRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26256985/

相关文章:

ios - Kingfisher nil 在展开可选值时

ios - 在目标 Controller 中设置类的属性

ios - Tiled - 支持不同的ios设备

ios - 找不到 Cocos2D kazmath/kazmath.h 文件

iphone - 如何保护 iOS bundle 文件

ios - 在模拟器中查看核心数据的内容

objective-c - Xcode & 网页 View : Load local html if no internet connection (fallback)

objective-c - iOS:比较两个没有时间部分的 NSDate-s

iphone - 从 NSData 打印 NSString 并比较 HMAC 哈希

ios - 阻止 super View 识别平移手势(在 iOS 7 中)