How to transition from one chapter to another?

孤街醉人 提交于 2020-12-07 06:46:06

问题


I have a webview. Everytime the user clicks on the next button, I load the webview with new content:

 webView.loadHTMLString(bodyText, baseURL: nil)

How do I create the following transition so that it seems like a new page is coming in from the right whenever a user clicks next?

See link for example

https://imgur.com/bCgk5qs

Here's what I have so far

let webViewToRemove = webView
let webViewToAdd = WKWebView()
webViewToAdd.frame = webViewToRemove?.frame as! CGRect
if (swipeLeft) {
    webViewToAdd.center = CGPoint(x: 2.0*self.view.bounds.width, y: webView.bounds.midY)
} else {
    webViewToAdd.center = CGPoint(x: -2.0*self.view.bounds.width, y: webView.bounds.midY)
}
webView = webViewToAdd
webView.loadHTMLString(bodyText, baseURL: nil)
self.view.addSubview(webViewToAdd)
UIView.animate(withDuration: 1.0, animations: {
    if (swipeLeft) {
        webViewToRemove?.center = CGPoint(x: -2.0*self.view.bounds.width, y: self.webView.bounds.midY)
    } else {
        webViewToRemove?.center = CGPoint(x: 2.0*self.view.bounds.width, y: self.webView.bounds.midY)
    }
    webViewToAdd.center = CGPoint(x: self.view.bounds.midX, y: self.webView.bounds.midY)
    }, completion: { finished in
        webViewToRemove?.removeFromSuperview()
})

回答1:


I have an app on the app store that behaves much as you seem to be describing. It shows its Help as web views loaded from html strings, just like what you are doing. The user can navigate right and left either with arrow buttons (top left) or by sliding manually with a finger. This screencast shows both; first I use the arrow buttons, then I slide manually:

How is that done? It's trivial; it's a UIPageViewController. No need to reinvent a wheel that Apple has already handed us.



来源:https://stackoverflow.com/questions/65050178/how-to-transition-from-one-chapter-to-another

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