UIScrollView subviews contents size issue

和自甴很熟 提交于 2019-12-13 07:35:02

问题


I am using a scrollView, in which i have added some static content in a container view and below this container view i have added a web view and added both these views into my scrollView, I dont want the web view to be scroll, instead I want that my scrollview should scroll according to the height of my container view and height of contents in web view.

Note: I am loading contents in webview as html string, that i am receiving from server, The contents are coming in between of html tags and i am then passing this as a string to web view.

Thanks


回答1:


try this code

  CGRect contentRect = CGRectZero;

  for (UIView *subview in scrollview.subviews ) {
    contentRect = CGRectUnion(contentRect,subview.frame);
  }

  scrollview.contentSize = CGSizeMake(scrollview.bounds.size.width, CGRectGetMaxY(contentRect));



回答2:


set scrollview Content Size as containerview height + webview height

and your webview Height must be equal to the content Size of that Webview because you don't want to scroll your webview.




回答3:


  1. find height of contents in webview
  2. make it the size of webview,containerview frame and scrollview contentsize
  3. disable scroll of webview


来源:https://stackoverflow.com/questions/17042004/uiscrollview-subviews-contents-size-issue

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