edwardmp
edwardmp

Reputation: 6611

Navigation bar glitch when using iOS 7 swipe navigation

I'm having a strange graphical glitch in my app when I use swiping to go back to the previous view.

When I swipe normally and complete the swipe gesture, everyting works fine.

When I cancel the swipe gesture, that is: starting the gesture but then move your finger in the opposite direction to stop the gesture and stay at the current view.

The glitch I'm getting that If I then go back to the previous screen, the barbutton items of that view overlap with the barbutton items from the previous view.

Screenshots: Starting point: enter image description here

Swiping back gesture and complete gesture, go to previous view, works correctly: enter image description here

Swiping back gesture and cancel gesture, thus stay on current screen, then go back to the previous screen, the text buttons overlap: enter image description here

This graphical glitch only disappears when force quitting the app and restarting it. But of course if you provoke the glitch again, it appears again.

Hope there are some developers that had the same problem.

Edit, cause of problem is the following code:

- (void)resetCacheAndRefreshTableAnimated:(BOOL)animated {
    [NSFetchedResultsController deleteCacheWithName:kCDFollowedCacheName];
    [self setSortDescriptorsForFetchRequest:self.fetchedResultsController.fetchRequest];
    NSError *error = nil;
    [self.fetchedResultsController performFetch:&error];
    [self.tableView reloadData];
}

This method is called in ViewWillAppear. When method call is removed, problem goes away. Any idea?

Upvotes: 2

Views: 643

Answers (2)

edwardmp
edwardmp

Reputation: 6611

Managed to figure out based on Vikram's reply and another question of StackOverflow.

So the problem was that [self.tableView reloadData] was called in ViewWillAppear. But tableview should not be reloaded when swipe is cancelled.

This code prevents reloading when swipe is cancelled:

id <UIViewControllerTransitionCoordinator> tc = self.transitionCoordinator;
if (tc && [tc initiallyInteractive])
{
    [tc notifyWhenInteractionEndsUsingBlock:
     ^(id<UIViewControllerTransitionCoordinatorContext> context)
     {
         if (![context isCancelled])
             // not cancelled, do it
             [self resetCacheAndRefreshTableAnimated:YES]; // this will clear the CoreData cache and forces a reload
     }];
}
else // not interactive, do it
    [self resetCacheAndRefreshTableAnimated:YES];       // this will clear the CoreData cache and forces a reload

Upvotes: 1

Vikram Rao
Vikram Rao

Reputation: 514

Probably you might not be clearing the moved view, and hence even if you cancelled the gesture in the middle of a movement, the view(s) already moved would not reset.

Upvotes: 0

Related Questions