【发布时间】:2017-11-23 22:43:53
【问题描述】:
问题:升级到更新的 Xcode 并支持 ios 11。 (我的应用不需要它,但 Apple 强制不再支持界面构建器文件 - 尝试将应用上传到应用商店时收到错误消息)。
代码看起来很简单(并非总是如此!)。 我创建了一个最小的示例并附上了它。 简单的单页应用程序。加载视图并识别一些手势。 所以单击手势有效。双击没有。 双击被识别为 2 次单击(可能是合理的)。 我删除了单击 getsure 并尝试触发 2 指 2 轻击手势的处理程序。 得不到认可。 两者都使用空 nib 文件为 ios5.x 工作。
这里是 appDelegate 文件:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
实现:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] ;
self.appViewController = [[myViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.appViewController;
//@property(nullable, nonatomic,strong) UIViewController *rootViewController NS_AVAILABLE_IOS(4_0); // from "UIWindow"
[self.window makeKeyAndVisible];
self.window.backgroundColor = [UIColor redColor];
return YES;
}
视图控制器:
@interface ViewController ()
@property (retain,readwrite) UITapGestureRecognizer *twoFingerDoubleTap_yyz;
@property (retain,readwrite) UITapGestureRecognizer *oneFinger;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//add gesture Double tap to open a view.
self.twoFingerDoubleTap_yyz = [[UITapGestureRecognizer alloc]initWithTarget:(id)self action:@selector ( twoFingerDoubleTap:) ];
[self.view addGestureRecognizer:self.twoFingerDoubleTap_yyz];
self.twoFingerDoubleTap_yyz.numberOfTapsRequired = 2;
self.twoFingerDoubleTap_yyz.numberOfTouchesRequired = 2;
/*
self.oneFinger = [[UITapGestureRecognizer alloc]initWithTarget:(id)self action:@selector ( oneFingerTap:) ];
[self.view addGestureRecognizer:self.oneFinger];
self.oneFinger.numberOfTapsRequired = 1;
self.oneFinger.numberOfTouchesRequired = 1;
*/
}
-(IBAction)twoFingerDoubleTap: (UITapGestureRecognizer *) sender
{
NSLog(@"i'm here 2 !");
}
-(IBAction)oneFingerTap: (UITapGestureRecognizer *) sender
{
NSLog(@"i'm here 1 !");
}
@end
代码看起来很简单,所以我想将问题归咎于Xcode(可能新9.1不识别双击?)或ios11。但由于我没有看到其他人有这个问题,我不得不认为我错过了一些东西——甚至可能很明显? (注意:我没有在真实设备上尝试过,因为目前我没有运行超过 ios7.x 的任何东西。我原来的 iPad 需要升级 - 终于!?)
更新:(从评论部分移到此处,因为它非常相关)两指单击也可以在测试中使用。只是不是两指双击!
【问题讨论】:
标签: ios objective-c xcode