在UIWeb视图的iOS中禁用垂直滚动弹跳?

时间:2014-11-02 19:04:38

标签: ios objective-c uiwebview

我有一个UIWebView,我用HTML代码填写。我将背景图像设置为UIWebView。我还设置了NO alwaysBounceVertical UIScrollView,但它继续反弹。

为什么?

我的代码:

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;

3 个答案:

答案 0 :(得分:1)

默认情况下,

alwaysBounceVerticalalwaysBounceHorizonal设置为NO,因此您的代码无效。

相反,您需要将bounces设置为NO,以禁用弹跳,即

self.wwTicket.scrollView.bounces = NO;

如果您的WebView框架和内容大小相同,也可以选择完全禁用滚动,即

self.wwTicket.scrollView.scrollEnabled = NO;

答案 1 :(得分:1)

我认为alwaysBounceHorizo​​nal和alwaysBounceVertical,实际上不会禁用弹跳。

如果此属性设置为YES并且弹跳为YES,则即使内容小于滚动视图的边界,也允许垂直拖动。默认值为NO。(Apple docs)。

此属性用于在内容大小小于scrollView大小时启用弹跳,

要禁用垂直反弹,您可以将其内容大小设置为垂直视图大小:

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

你可以禁用所有弹跳,就像预览答案一样。

答案 2 :(得分:1)

xcode 7,swift 2.0,

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

        webview.scrollView.bounces = false;