挑选& pop force touch手势有时不起作用

时间:2015-11-04 13:38:05

标签: ios objective-c force-touch

我有一个视图控制器,它在viewDidLoad方法中注册预览:

- (void) viewDidLoad
{
    [super viewDidLoad];

    if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] &&
        (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
    {
        [self registerForPreviewingWithDelegate:self sourceView:self.view];
    }
}

但有时无法识别强制触摸,因为视图控制器未注册预览。

1 个答案:

答案 0 :(得分:4)

问题是从状态恢复启动应用程序。 修复:在viewWillAppear中放置预览注册代码:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] &&
        (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
    {
        [self registerForPreviewingWithDelegate:self sourceView:self.view];
    }
}

从状态恢复调用viewDidLoad时,正确的时间是注册预览。