简体   繁体   中英

In iOS in UIWeb view disable vertical scroll bounce?

I have an UIWebView which I fill with HTML code. I set up background image to that UIWebView . I also set up NO to alwaysBounceVertical of its UIScrollView , but it continues to bounce.

Why?

MY CODE:

NSMutableString *properTicketText = [NSMutableString string];
[properTicketText appendString:@"<!DOCTYPE html> \n"];
[properTicketText appendString:@"<html> \n"];
[properTicketText appendString:@"<head> \n"];
[properTicketText appendString:@"<style> \n"];
[properTicketText appendString:@"#my { \n"];
[properTicketText appendString:@"width: 280px; \n"];
[properTicketText appendString:@"   padding-left: 20px; \n"];
[properTicketText appendString:@"   padding-right: 0px; \n"];
[properTicketText appendString:@"} \n"];
[properTicketText appendString:@"</style> \n"];
[properTicketText appendString:@"</head> \n"];
[properTicketText appendString:@"<body> \n"];
[properTicketText appendString:@"<div id=\"my\"> \n"];

[properTicketText appendString:singApp.operationTicketData];
[properTicketText appendString:@"\n"];

[properTicketText appendString:@"</div> \n"];
[properTicketText appendString:@"</body> \n"];
[properTicketText appendString:@"</html> \n"];

// Set lblServiceDescriptions label multiline
_lblInfo.lineBreakMode = NSLineBreakByWordWrapping;
_lblInfo.numberOfLines = 0;

[self.wwTicket loadHTMLString:[NSString stringWithString:properTicketText] baseURL:nil];

self.wwTicket.clipsToBounds = NO;

[self.wwTicket setOpaque:NO];
[self.wwTicket setBackgroundColor:
 [UIColor colorWithPatternImage:[UIImage imageNamed:@"ticket_paper2.png"]]];

self.wwTicket.scrollView.alwaysBounceVertical =  NO;
self.wwTicket.scrollView.alwaysBounceHorizontal =  NO;

alwaysBounceVertical and alwaysBounceHorizonal is set to NO by default, so your code have no effect.

Instead, you need to set bounces to NO, to disable bouncing, ie

self.wwTicket.scrollView.bounces = NO;

You can optionally also disable scrolling entirely, if your WebView frame and content are of the same size, ie

self.wwTicket.scrollView.scrollEnabled = NO;

I think that alwaysBounceHorizonal and alwaysBounceVertical, actually, will not disable bouncing.

If this property is set to YES and bounces is YES, vertical dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NO.(Apple docs).

This property used to enable bouncing if content size smaller than scrollView size,

to disable vertical bounce, you can set it content size in vertical to view size:

self.wwTicket.scrollView.contentSize = CGSizeMake(self.wwTicket.scrollView.frame.size.width, self.wwTicket.scrollView.contentSize.height);

of you can disable all bouncing, like in previews answer.

xcode 7, swift 2.0,

@IBOutlet weak var webview: UIWebView!
    override func viewDidLoad() {

        webview.scrollView.bounces = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM