tag:blogger.com,1999:blog-865923359735383241.post2923781607550379550..comments2023-10-29T07:27:09.012-06:00Comments on Ccna final exam - java, php, javascript, ios, cshap all in one: Stop UIWebView from "bouncing' vertically?Unknownnoreply@blogger.comBlogger13125tag:blogger.com,1999:blog-865923359735383241.post-59480744316229954112012-05-30T03:59:42.198-06:002012-05-30T03:59:42.198-06:00One of the subviews of UIWebView should be a UIScr...One of the subviews of UIWebView should be a UIScrollView. Set its scrollEnabled property to NO and the web view will have scrolling disabled entirely.<br /><br />Note: this is technically using a private API and thus your app could be rejected or crash in future OS releases. Use @try and respondsToSelectorUserhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-85231450977772207342012-05-30T03:59:39.144-06:002012-05-30T03:59:39.144-06:00I was annoyed to find out that UIWebView is not a ...I was annoyed to find out that UIWebView is not a scroll view, so I made a custom subclass to get at the web view's scroll view. This suclass contains a scroll view so you can customize the behavior of your web view. The punchlines of this class are:<br /><br />@class CustomWebView : UIWebview<br />...<br /><br />- (id) initWithFrame:(CGRect)frame{<br />self = [super initWithFrame:frame];<br />// WebViews are subclass of NSObject and not UIScrollView and therefore don't allow customization.<br />// However, a UIWebView is a UIScrollViewDelegate, so it must CONTAIN a ScrollView somewhere.<br />// To use a web view like a scroll view, let's traverse the view hierarchy to find the scroll view inside the web view.<br />for (UIView* v in self.subviews){<br /> if ([v isKindOfClass:[UIScrollView class]]){<br /> _scrollView = (UIScrollView*)v; <br /> break;<br /> }<br />}<br />return self;<br /><br /><br />}<br /><br />Then, when you create a custom web view, you can disable bouncing with:<br /><br />customWebView.scrollView.bounces = NO; //(or customWebView.scrollView.alwaysBounceVertically = NO)<br /><br /><br />This is a great general purpose way to make a web view with customizable scrolling behavior. There are just a few things to watch out for:<br /><br /><br />as with any view, you'll also need to override -(id)initWithCoder: if you use it in Interface Builder<br />when you initially create a web view, its content size is always the same as the size of the view's frame. After you scroll the web, the content size represents the size of the actual web contents inside the view. To get around this, I did something hacky - calling -setContentOffset:CGPointMake(0,1)animated:YES to force an unnoticeable change that will set the proper content size of the web view.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-24184151906291450922012-05-30T03:59:38.129-06:002012-05-30T03:59:38.129-06:00http://doctyper.com/archives/200808/fixed-position...http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/<br /><br />This link helped me lot.....Its easy.. There is a demo..Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-19853099628225951942012-05-30T03:59:36.589-06:002012-05-30T03:59:36.589-06:00Here's two newer potential solutions. Apparent...Here's two newer potential solutions. Apparently, you can use jqtouch or pastrykit to disable scrolling. However, I haven't got these to work. You might be more competent.<br /><br />http://blog.jqtouch.com/post/285889760/turning-off-vertical-scrolling<br /><br />http://waynepan.com/2009/12/16/digging-into-pastrykitUserhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-24024845330396940922012-05-30T03:59:35.358-06:002012-05-30T03:59:35.358-06:00In the iOS 5 SDK you can access the scroll view as...In the iOS 5 SDK you can access the scroll view associated with a web view directly rather than iterating through its subviews.<br /><br />So to disable 'bouncing' in the scroll view you can use:<br /><br />myWebView.scrollView.bounces = NO;<br /><br /><br />See the UIWebView Class Reference.<br /><br />(However if you need to support versions of the SDK before 5.0, you should follow Mirek Rusin's advice.)Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-8641700091019095442012-05-30T03:59:34.630-06:002012-05-30T03:59:34.630-06:00On iOS5 only if you plan to let the users zoom the...On iOS5 only if you plan to let the users zoom the webview contents (e.i.: double tap) the bounce setting isn't enough. You need to set also alwaysBounceHorizontal and alwaysBounceVertical properties to NO, else when they zoom-out (another double tap...) to default it will bounce again.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-48640802173318921822012-05-30T03:59:33.667-06:002012-05-30T03:59:33.667-06:00I traversed the collection of UIWebView's subv...I traversed the collection of UIWebView's subviews and set their backgrounds to [UIColor blackColor], the same color as the webpage background. The view will still bounce but it will not show that ugly dark grey background.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-43607881399708579302012-05-30T03:59:30.551-06:002012-05-30T03:59:30.551-06:00Brad's method worked for me. If you use it you...Brad's method worked for me. If you use it you might want to make it a little safer.<br /><br />id scrollView = [yourWebView.subviews objectAtIndex:0];<br />if( [scrollView respondsToSelector:@selector(setAllowsRubberBanding:)] )<br />{<br /> [scrollView performSelector:@selector(setAllowsRubberBanding:) withObject:NO];<br />}<br /><br /><br />If apple changes something then the bounce will come back - but at least your app won't crash.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-79106872705256117022012-05-30T03:59:28.337-06:002012-05-30T03:59:28.337-06:00Warning. I used setAllowsRubberBanding: in my app...Warning. I used setAllowsRubberBanding: in my app, and Apple rejected it, stating that non-public API functions are not allowed (cite: 3.3.1)Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-52635067987667744762012-05-30T03:59:26.669-06:002012-05-30T03:59:26.669-06:00If your webview doesnt need scrolling and doesnt n...If your webview doesnt need scrolling and doesnt need to handle links, you can set<br /><br />mywebview.userInteractionEnabled = FALSE<br /><br /><br />so your webview will not respond to touches.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-74722657149092360802012-05-30T03:59:22.851-06:002012-05-30T03:59:22.851-06:00Well all I did to accomplish this is :
[[webView....Well all I did to accomplish this is :<br /><br />[[webView.subviews objectAtIndex:0] setScrollEnabled:NO]; //to stop scrolling completely<br />[[webView.subviews objectAtIndex:0] setBounces:NO]; //to stop bouncing<br /><br /><br />Works fine for me... <br />Also, the ticked answer for this question is one that Apple will reject if you use it in<br />your iphone app.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-24192211949950930942012-05-30T03:59:20.918-06:002012-05-30T03:59:20.918-06:00I tried all of the above approaches, with no succe...I tried all of the above approaches, with no success... but I was looking at a project that makes it easy to create web apps as full fledged installable applications on the iPhone called QuickConnect, and found a solution that works, if you don't want your screen to be scrollable at all, which in my case I didn't.<br /><br />In the above mentioned project/blog post, they mention a javascript function you can add to turn off the bouncing, which essentially boils down to this:<br /><br /> document.ontouchmove = function(event){<br /> event.preventDefault();<br /> }<br /><br /><br />If you want to see more about how they implement it, simply download QuickConnect and check it out.... But basically all it does is call that javascript on page load... I tried just putting it in the head of my document, and it seems to work fine.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-37643325426395456722012-05-30T03:59:20.003-06:002012-05-30T03:59:20.003-06:00for (id subview in webView.subviews)
if ([[subvi...for (id subview in webView.subviews)<br /> if ([[subview class] isSubclassOfClass: [UIScrollView class]])<br /> ((UIScrollView *)subview).bounces = NO;<br /><br /><br />...seems to work fine.<br /><br />It'll be accepted to App Store as well.<br /><br />UPD: there's an easier way from ios 5.0:<br />now UIWebView has UIScrollView property, so your code should look like this:<br /><br />webView.scrollView.bounces = NO;Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.com