UIKit & graphicsHistorical technical note

Disabling the system swipe-back gesture on iOS

Addresses an embedded game unexpectedly revealing navigation and tab bars during a swipe. The article shows where to control the navigation controller's built-in back gesture and records how that interaction was disabled for a particular screen.

Author:

Originally credited to Bison. Content is retained as published.

English translation of the Chinese original, translated on . The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

"Health is the foundation of everything. Getting more exercise is the way to go." Bison

A recent project contained an embedded game and had this issue: swiping left made the navigation bar and tabbar appear. That led to the code below.

The code is as follows

Core code

// 禁用返回手势,需要开启只需设置为yes即可。默认开启  

if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {  
self.navigationController.interactivePopGestureRecognizer.enabled = NO;  
}