탐색 컨트롤러로 보기로 돌아가기 위해 자동 제스처를 끄는 방법은 무엇입니까? (How to turn off the automatic gesture to go back a view with a navigation controller?)


문제 설명

탐색 컨트롤러로 보기로 돌아가기 위해 자동 제스처를 끄는 방법은 무엇입니까? (How to turn off the automatic gesture to go back a view with a navigation controller?)

그래서 사용자가 화면의 맨 왼쪽(어느 방향에서든)을 스와이프하면(이것은 iOS7의 새로운 기능입니다. )

지금까지 다음을 사용하여 끄려고 시도했지만 소용이 없었습니다.

    [self.navigationItem setHidesBackButton:YES];

NavigationController 자체의 초기화 내에서(대리자가 이를 사용하는 것처럼 보임)


참조 솔루션

방법 1:

obj‑c

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

swift

navigationController?.interactivePopGestureRecognizer?.isEnabled = false

방법 2:

Adding to Gabriele's Solution.

To support any iOS before iOS 7 you will need to wrap this code with this:

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

This will stop the App crashing in iOS 6 and iOS 5 for missing selector.

방법 3:

I use this solution in my project, it disables only interactivePopGestureRecognizer and allows you to use another gesture recognizers.

‑ (void)viewDidLoad {

    [super viewDidLoad];

    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;

    }

}


‑ (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    if ([gestureRecognizer isEqual:self.navigationController.interactivePopGestureRecognizer]) {

        return NO;

    } else {

        return YES;

    }

}

방법 4:

I found out setting the gesture to disabled only doesn't always work. It does work, but for me it only did after I once used the backgesture. Second time it wouldn't trigger the backgesture.

Fix for me was to delegate the gesture and implement the shouldbegin method to return NO:

‑ (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Disable iOS 7 back gesture
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
}

‑ (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    // Enable iOS 7 back gesture
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
}

‑ (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return NO;
}

방법 5:

For IOS 8 (Swift):

class MainNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer.enabled = false

        // Do any additional setup after loading the view.
    }

}

(by Danoli3Gabriele PetronellaDanoli3UserichAntoineilan)

참조 문서

  1. How to turn off the automatic gesture to go back a view with a navigation controller? (CC BY‑SA 3.0/4.0)

#ios7 #XCode #objective-c #iOS






관련 질문

iOS 7 Safari 사용자 에이전트를 결정하는 가장 좋은 방법은 무엇입니까? (What is the best way to determine iOS 7 Safari user agent?)

iOS 7, 탐색바가 반투명하지 않습니다... 더보기 탭이 반투명하게 보이는 이유는 무엇입니까? (iOS 7, navigation bar has no translucency... why does More tab look translucent?)

사진 촬영 후 사진 사용 또는 재촬영을 선택할 수 없습니다. (After Taking Picture cannot select Use Photo or Retake)

구문 분석 문제: 'stringByAppendingFormat' 모듈을 찾을 수 없습니다. (Parse Issue: Module 'stringByAppendingFormat' not found)

탐색 컨트롤러로 보기로 돌아가기 위해 자동 제스처를 끄는 방법은 무엇입니까? (How to turn off the automatic gesture to go back a view with a navigation controller?)

IOS 7 + 강제 컨트롤러의 경우 세로 방향 (IOS 7 + For force controller Orientation to Portrait)

Phonegap 앱은 iOS7에서 실행되지 않습니다. (Phonegap App doesn't run on iOS7)

UITableViewCellStyle2 색조 색상 설정 (Setting UITableViewCellStyle2 Tint Color)

iOS - flexbox 내부에 입력 요소가 있는 부동 커서 (iOS - Floating cursor with input elements inside flexbox)

UITableView는 iOS 7에서 작동하지만 iOS 8에서는 깨져 보입니다. (UITableView works in iOS 7 but appears crushed in iOS 8)

핵심 데이터 튜토리얼 (Core data tutorial)

StoryBoard를 사용하여 UITableViewCell 내부에 collectionView를 빠르게 빌드하는 방법 (How to use StoryBoard quick build a collectionView inside UITableViewCell)







코멘트