3

I just trying to get to QLPreviewController.view. Indeed, I want to catch a tap event on its view to show/hide toolbar etc. I am trying:

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 attach UITapRecognizer onto navigationController.view, it fires only if I touch toolbar/navbar. UISwipeGestureRecognizer works fine in that case.

I tried to attach a transparent overlay view and add gesture recognizers on it, but no luck. Well, I saw some apps that implements such a feature so obviously it is possible, but how? Sorry, I googled all day long and didn't find any solution. Please, help me.

4

6 に答える 6

1

あなたのソリューションでは、QLPreviewControllerのビューはまだタッチを受け取りますか?私は似たようなことをしようとしました(QLPreviewControllerからビューを盗んで使用しています)。オーバーレイビューでは、背後にあるビューに何も通過しないようです。

于 2011-09-14T08:27:17.193 に答える
1

私は今日この問題に取り組んでおり、-(void)contentWasTappedInPreviewContentController:(id)item {}をオーバーライドする提案は近いですが、プレビューコントローラーの処理を台無しにします。

そのため、そのメソッドのオーバーライドを停止し、代わりに、メソッドが呼び出されるたびに起動するRACシグナルを作成しました。これは、QLのデフォルトの動作を台無しにすることはありません。QLPreviewControllerのサブクラスで実行していますが、これは必要ありません。

クラスにプロパティがあります:

 @property RACSignal *contentTapped;

次に、QLPreviewControllerのサブクラスのinitメソッドで:

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

別のクラスで、または内部でさえ、次のような信号を使用できます。

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 に答える
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 に答える