View QLPreviewController

I'm just trying to get to QLPreviewController.view. In fact, I want to catch the tap event on its view, to show / hide the toolbar, etc. I'm trying to:

QLPreviewController* qlpc = [QLPreviewController new];
    qlpc.delegate = self;
    qlpc.dataSource = self;
    qlpc.currentPreviewItemIndex=qlIndex;
    [navigator pushViewController:qlpc animated:YES];
    qlpc.title = [path lastPathComponent];
    [qlpc setToolbarItems:[NSArray arrayWithObjects:self.dirBrowserButton,self.space, self.editButton, self.btnSend, nil] animated:YES];
    UITapGestureRecognizer* gestTap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showControls:)];
    gestTap.cancelsTouchesInView=NO;
    [qlpc.view addGestureRecognizer:[gestTap autorelease]];
    [qlpc release];

And nothing happens

If I connect the UITapRecognizer to navigationController.view, it only works if I touch the toolbar / navigation bar. UISwipeGestureRecognizer works fine in this case.

I tried to attach a transparent overlay view and add gesture recognizers to it, but no luck. Well, I saw some applications that implement such a function, so obviously this is possible, but how? Sorry, I googled all day and did not find any solution. Please help me.

+3
source share
6

, , , , QLPreviewController viewDidAppear :

- (void)viewDidAppear:(BOOL)animated
{ 
    UITapGestureRecognizer *gestTap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showControls:)];
    gestTap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:[gestTap autorelease]];
}
0

QLPreviewController - ? - ( QLPreviewController, ), , , .

+1

, - (void) contentWasTappedInPreviewContentController: (id) item {} , .

, RAC-, , . QL . QLPreviewController, .

:

 @property RACSignal *contentTapped;

init QLPreviewController:

_contentTapped = [self   rac_signalForSelector:@selector(contentWasTappedInPreviewContentController:)];

:

previewController.contentTapped subscribeNext:^(id x) {
    // Put your handler here!
}];
+1

( KVO), , (, )

#define kNavigationBarKeyPath @"navigationBar.hidden"

static void * const NavigationBarKVOContext = (void*)&NavigationBarKVOContext;

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

    [self.navigationController setToolbarHidden:NO];
    [self.navigationController addObserver:self forKeyPath:kNavigationBarKeyPath options:NSKeyValueObservingOptionPrior context:NavigationBarKVOContext];
}

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

    [self.navigationController removeObserver:self forKeyPath:kNavigationBarKeyPath];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ( context == NavigationBarKVOContext ) {
        BOOL prior = [change[NSKeyValueChangeNotificationIsPriorKey] boolValue];
        if ( prior && self.navigationController.toolbarHidden ) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController setToolbarHidden:NO animated:YES];
            });
        }
    }
}
+1

Well, the solution is very simple. just added an overlay view of keyWindow. Attached gesture recognizers overlap and work.

        QLPreviewController* qlpc = [QLPreviewController new];
    qlpc.delegate = self;
    qlpc.dataSource = self;
    qlpc.currentPreviewItemIndex=qlIndex;
    [navigator pushViewController:qlpc animated:YES];
    qlpc.title = [path lastPathComponent];
    UIView* overlay = [[[UIView alloc] initWithFrame:navigator.view.bounds] autorelease];
    [[[UIApplication sharedApplication] keyWindow] addSubview:overlay];
    [overlay setNeedsDisplay];
    [qlpc setToolbarItems:[NSArray arrayWithObjects:self.dirBrowserButton,self.space, self.editButton, self.btnSend, nil] animated:YES];
    UITapGestureRecognizer* gestTap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showControls:)];
    gestTap.cancelsTouchesInView=NO;
    [overlay addGestureRecognizer:[gestTap autorelease]];
    [qlpc release];
0
source

Subclass QLPreviewController and then override

- (Invalid) contentWasTappedInPreviewContentController: (identifier) ​​clause {}

Here it is!

-1
source

All Articles