使用链接隐藏/显示UIToolbar / Navbar

时间:2023-01-07 01:29:45

I'm using Photoswipe in my app and it is working very nice. Right now I have a toolbar and a navbar, so when viewing the photos in "fullscreen" the toolbar and navbar is still visible, so the it is not actually a fullscreen. I'm wondering however if it could be possible to hide/show the toolbar/navbar depending on when an image is clicked/dismissed.

我在我的应用程序中使用Photoswipe,它工作得非常好。现在我有一个工具栏和一个导航栏,因此当在“全屏”中查看照片时,工具栏和导航栏仍然可见,因此它实际上不是全屏。我想知道是否可以隐藏/显示工具栏/导航栏,具体取决于图像被点击/解除的时间。

I found this which will hide the toolbar

我发现这将隐藏工具栏

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {

        self.navController.hidden = YES;

    }
    return YES;
}

So far so good, but how do I get the toolbar back when the user clicks the exit button in Photoswipe (which is essential just another link)?

到目前为止一切都那么好,但是当用户点击Photoswipe中的退出按钮时,如何恢复工具栏(这只是另一个链接)?

Any help is appreciated!

任何帮助表示赞赏!

1 个解决方案

#1


0  

I tend to find that relying on UIWebViewNavigationTypeLinkClicked or indeed any kind of webView:shouldStartLoadWithRequest: is going to give you inconsistent results. I recommend using JSBridge, with which you can create a dictionary object that will be passed to Cocoa. With this, you can guarantee capturing the event and load your event with custom information for it.

我倾向于发现依赖于UIWebViewNavigationTypeLinkClicked或者任何类型的webView:shouldStartLoadWithRequest:会给你不一致的结果。我建议使用JSBridge,您可以使用它创建一个将传递给Cocoa的字典对象。有了这个,您可以保证捕获事件并使用自定义信息加载事件。

For this, you create a JSBridgeWebView (subclass of UIWebView) and setup the delegate to handle:

为此,您创建一个JSBridgeWebView(UIWebView的子类)并设置委托来处理:

-(void) webView:(UIWebView*)webView didReceiveJSNotificationWithDictionary:(NSDictionary*) dictionary { 
    NSLog(@"Received notification dictionary %@", dictionary);
}

Then add in a quick JavaScript function:

然后添加一个快速的JavaScript函数:

function sendShowToolBarNotification() { 
    var obj = new JSBridgeObj();
    obj.addObject("eventName", "showToolBar");
    obj.sendBridgeObject();
}

Now you can have a link that will send this notification to your application:

现在,您可以拥有一个链接,将此通知发送到您的应用程序:

<a href="javascript:sendShowToolBarNotification()">Click here to show toolbar</a>

#1


0  

I tend to find that relying on UIWebViewNavigationTypeLinkClicked or indeed any kind of webView:shouldStartLoadWithRequest: is going to give you inconsistent results. I recommend using JSBridge, with which you can create a dictionary object that will be passed to Cocoa. With this, you can guarantee capturing the event and load your event with custom information for it.

我倾向于发现依赖于UIWebViewNavigationTypeLinkClicked或者任何类型的webView:shouldStartLoadWithRequest:会给你不一致的结果。我建议使用JSBridge,您可以使用它创建一个将传递给Cocoa的字典对象。有了这个,您可以保证捕获事件并使用自定义信息加载事件。

For this, you create a JSBridgeWebView (subclass of UIWebView) and setup the delegate to handle:

为此,您创建一个JSBridgeWebView(UIWebView的子类)并设置委托来处理:

-(void) webView:(UIWebView*)webView didReceiveJSNotificationWithDictionary:(NSDictionary*) dictionary { 
    NSLog(@"Received notification dictionary %@", dictionary);
}

Then add in a quick JavaScript function:

然后添加一个快速的JavaScript函数:

function sendShowToolBarNotification() { 
    var obj = new JSBridgeObj();
    obj.addObject("eventName", "showToolBar");
    obj.sendBridgeObject();
}

Now you can have a link that will send this notification to your application:

现在,您可以拥有一个链接,将此通知发送到您的应用程序:

<a href="javascript:sendShowToolBarNotification()">Click here to show toolbar</a>