WGEditor-mobile icon indicating copy to clipboard operation
WGEditor-mobile copied to clipboard

提供一个自动换行方法

Open iOSliusen opened this issue 6 years ago • 1 comments

//自动换行方法,仅供参考


//webView代理方法
- (void)webViewDidFinishLoad:(UIWebView *)webView {

    
    /*
     
     Callback for when text is changed, solution posted by richardortiz84 https://github.com/nnhubbard/ZSSRichTextEditor/issues/5
     
     */
//需要引入头文件 : @import JavaScriptCore;
    JSContext *ctx = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    ctx[@"contentUpdateCallback"] = ^(JSValue *msg) {
        [self.webView autoScrollTop:[self.webView getCaretYPosition]];
    };
    [ctx evaluateScript:@"document.getElementById('article_content').addEventListener('input', contentUpdateCallback, false);"];
}

iOSliusen avatar Nov 29 '18 06:11 iOSliusen

我也是copy了ZSSRichTextEditor这个方法, 不过[self.webView getCaretYPosition]返回的是顶部位置,需要减去编辑空白区(屏幕高度-导航-键盘-iPhone X底部高度-barView高度 等等)

切换fonBar再重新更新光标位置,其他根据需求优化了一下.

teaold avatar Jan 21 '19 09:01 teaold