UIDocumentInteractionController remove Actions Menu

落花浮王杯 提交于 2019-12-06 00:15:50

Use UINavigationControllerDelegate

@interface DITableViewController () <UIDocumentInteractionControllerDelegate, UINavigationControllerDelegate>

Assign navigationController delegate to self

- (void)viewDidLoad {

    [super viewDidLoad];
    self.navigationController.delegate = self;
}

Change documentInteractionControllerViewControllerForPreview

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)interactionController {

    return self.navigationController;
}

Add this UINavigationControllerDelegate method

// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

    if ([viewController isKindOfClass:[QLPreviewController class]]) {
        viewController.navigationItem.rightBarButtonItem = nil;
    }
}

Update for MP4 files

In MP4 files the action button is on the UIToolbar

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([viewController isKindOfClass:[QLPreviewController class]]) {
        viewController.navigationItem.rightBarButtonItem.customView = [[UIView alloc] init];
        UIBarButtonItem *item = viewController.toolbarItems.firstObject;
        item.customView = [[UIView alloc] init];
    }
}

N.B. This might not work in future versions of iOS

After creating QLPreviewController class you would need to set rightBarButtonItem to nil. Code snippet:

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.navigationItem.rightBarButtonItem = nil;

I did download project and after execution "Action" button was shown not in the top navigation item, but in the toolbar. Then in this case you would need to subclass QLPreviewController and override viewWillAppear as shown below.

@implementation ExViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSMutableArray *a = [NSMutableArray arrayWithArray:@[]];
    for (NSUInteger i = 0; i < self.toolbarItems.count; i++) {
        if (i == 0) {
            continue;
        }
        [a addObject:self.toolbarItems[i]];
    }
}

@end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!