3

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

- (void) viewDidLoad
{
    [super viewDidLoad];

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

但有时无法识别强制触摸,就好像视图控制器没有注册预览一样。

4

1 回答 1

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 时,正是注册预览的时机。

于 2015-11-04T13:38:04.757 回答