mixtly87
mixtly87

Reputation: 1695

Pick & pop force touch gesture not working sometimes

I have a view controller which registers for previewing in viewDidLoad method:

- (void) viewDidLoad
{
    [super viewDidLoad];

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

but sometimes force touch is not recognized as if view controller didn't register for previewing.

Upvotes: 3

Views: 368

Answers (1)

mixtly87
mixtly87

Reputation: 1695

The problem was starting the app from state restoration. Fix: place preview registering code in viewWillAppear:

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

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

When viewDidLoad is called from state restoration, the timing is right for registering for previewing.

Upvotes: 4

Related Questions