3

我只是想进入 QLPreviewController.view。事实上,我想在其视图上捕捉一个点击事件以显示/隐藏工具栏等。我正在尝试:

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];

什么也没有发生

如果我将 UITapRecognizer 附加到 navigationController.view 上,它只会在我触摸工具栏/导航栏时触发。UISwipeGestureRecognizer 在这种情况下工作正常。

我试图附加一个透明的覆盖视图并在其上添加手势识别器,但没有运气。好吧,我看到一些应用程序实现了这样的功能,很明显这是可能的,但是怎么做呢?抱歉,我搜索了一整天,没有找到任何解决方案。请帮我。

4

6 回答 6

1

I have been working on this problem today and the suggestion to override -(void)contentWasTappedInPreviewContentController:(id)item {} is close but when you do you mess with the preview controllers handling.

So I stopped overriding that method and instead created a RAC signal that fires whenever the method is called. This does not mess with the default behavior of QL. I am doing it in a subclass of the QLPreviewController but that shouldn't be necessary.

I have a property on my class:

 @property RACSignal *contentTapped;

Then in my init method of my subclass of QLPreviewController:

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

Now in another class or even internally you can use the signal like this:

previewController.contentTapped subscribeNext:^(id x) {
    // Put your handler here!
}];
于 2014-03-06T17:29:34.463 回答
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];
            });
        }
    }
}
于 2014-06-23T13:13:11.773 回答
1

使用您的解决方案,QLPreviewController 的视图是否仍会收到触摸?我试图做类似的事情(我正在从 QLPreviewController 窃取视图以使用它),看起来我的覆盖视图不会让任何东西通过它背后的视图。

于 2011-09-14T08:27:17.193 回答
0

好的,解决方案很简单。刚刚在 keyWindow 上添加了一个覆盖视图。将手势识别器附加到叠加层上,它可以工作。

        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];
于 2011-05-27T14:26:33.123 回答
0

我发现这里没有任何答案可以工作,但对我来说是子类化 QLPreviewController 并覆盖 viewDidAppear 如下:

- (void)viewDidAppear:(BOOL)animated
{ 
    UITapGestureRecognizer *gestTap  = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showControls:)];
    gestTap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:[gestTap autorelease]];
}
于 2011-11-23T01:42:02.027 回答
-1

子类 QLPreviewController 然后覆盖

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

就是它!

于 2014-02-06T16:28:27.043 回答