danh
danh

Reputation: 62676

UIScrollView type access to UIWebView

I'd like to know a UIWebView's contentOffset, and/or get didScroll type notifications from it. Am I missing something, or is that impossible.

The thing I'm going for is a UI that's half info panel, half UIWebView. When the app finds out that the user wants to see more of the web view, I'd like to reframe with a smaller info panel and larger web view. When user wants to see less, reframe to half and half.

The problem is the interface is pretty much out of button space. If the web view were a scroll view, I could use scroll actions to discern intent. (scroll down means enlarge, scroll above the top means reduce). Any ideas how I can achieve this with a web view?

Upvotes: 0

Views: 343

Answers (2)

Roshit
Roshit

Reputation: 1579

UIWebView is made up of UIScrollView.

to access the ScrollView you could use either of the two ways :

UIWebView *aWebView; // Initialization code 
UIScrollView *aScrollView;
for (UIView *aView in [aWebView subviews]) {
    if ([aView isKindOfClass:[UIScrollView class]]) {
        aScrollView = (UIScrollView *)aView;
    }
}

OR

aScrollView = [[aWebView subviews] objectAtIndex:0];

Option-1 is a safer way to get the UIScrollView instance...

AND....

If you are building your app for iOS5, you could just call..

aScrollView = aWebView.scrollView;

EDIT

If you check UIWebView in detail, you should have noticed that it conforms to UIScrollViewDelegate

Upvotes: 1

sigman
sigman

Reputation: 1301

If your primary intent is to provide custom gesture-type action on top of the UIWebView, you can try UIGestureRecognizer.

(Do not forget to provide UIGestureRecognizerDelegate's gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer implementation to allow webview own gesture recognizers to work properly)

Upvotes: 0

Related Questions