0

I'm using EGO Pull and Refresh code as described here to implement "Pull down to refresh" feature to UIWebView. All works fine, until I zoom webView.

If I add child to webView.scrollView it scrolls fine, but does not resize when webView zoomed. It stays absolutely the same size. Ever if I set autoresizeMask to FlexibleWidth or set autoresizeSubviews to YES.

EDIT:

It other words my question is: WHY WebView content zooming OK, while my own views, added to the same place (in UIWebView) don't? Also, why it is scrolling OK, but not zooming?

enter image description here

Community
  • 1
  • 1
Mike Keskinov
  • 11,614
  • 6
  • 59
  • 87
  • The web view zooming happens within the web view, so the resize is not the web view frame or the scroll view frame, so your EGO view will not resize. – Matt May 25 '12 at 21:14
  • It is not correct. `UIWebView` contains `UIScrollView`. Scroll view contains both components who render webView's content and one component I just added (EGO view or any other view). It is `UIScrollView` who manager zooming. You can ensure by looking at `zoomScale` property of `UIScrollView` - it is changing while zooming. – Mike Keskinov May 25 '12 at 23:58
  • Right, but the zooming is an adjustment to the content size, not the actual frame size of the scroll view. – Matt May 26 '12 at 00:02
  • Please explain it in more details. I don't get it. – Mike Keskinov May 26 '12 at 00:04

1 Answers1

1

This is more of an explanation to what is going on than a way to implement your intended behavior:

The scroll view has a frame which is essentially the viewing window into the content the scroll view contains. When you add a subview to a scrollview, the view is "added" (the implementation is unclear) to the scrollview's content view, which is generally larger than the scroll view's frame. The content offset of the scrollview, combined with the size of the scroll view's frame determines what portion of the content view is visible. When you zoom the web view, the content view size is changing, but your EGO view will not get a resize message because either the content view is not a true UIView, or the scroll view is blocking the resizing of it's subviews somehow (just a guess on the implementation). This is what would be expected because you might want to adjust what is inside the scroll view and by extension the size of the combined content without adjusting the size of each individual piece.

There might be an easier way than the following suggestion:

If you weren't dealing with a web view, and only a scroll view, you could subclass UIScrollView and override setContentSize to manually resize your EGO view with it. However, since you can't just swap out the scrollview inside the web view, you might look into using method swizzling to swap out the implementation of the setContentSize method of the web view's scroll view.

However, if I were you, I would think about why you want the EGO view to resize in the first place. It's not part of the content of the web view, but an action a user can take to modify that content...so it would seem you would want it to retain a readable/usable size. YOu might also consider the content of the web view and if you need to allow a user to resize that in the first place. With a standard news feed, it might be better to just lock it into the ideal viewing size.

EDIT:

After viewing your diagram, it looks like what you want isn't to resize the EGO view, but alter it's position so that it is always centered at the top of your web view. The safest way to do that, would be to become the delegate of the web view's scroll view, keep track of whatever the original delegate was (to be implementation independent (to a degree)) and forward all protocol methods to the original delegate. Then, in the scrollViewDidScroll method (and or scrollViewDidZoom, etc.. whatever is needed), you can set the origin.x of the EGO frame to contentOffset.x.

Matt
  • 1,586
  • 8
  • 12