【问题标题】:Lvalue error when attempting to change webview.bounds.origin.x/y尝试更改 webview.bounds.origin.x/y 时出现左值错误
【发布时间】:2011-09-23 12:37:40
【问题描述】:

所以基本上,我正在尝试创建一个 NSTimer,它将滚动浏览 UIWebView(这里命名为 _webView)。计时器正确触发,但其他行给了我一个“需要左值作为赋值的左操作数”错误。我要做的就是在每次 NSTimer 触发时将原点的 y 坐标增加 10 倍。这里出了什么问题?

NSLog(@"Value of webView.bounds.origin.y = %f", _webView.bounds.origin.y);
CGPoint topLeft = {_webView.bounds.origin.x, _webView.bounds.origin.y};
topLeft.y = topLeft.y + 10;
_webView.bounds.origin = topLeft;

【问题讨论】:

    标签: ios objective-c xcode bounds


    【解决方案1】:

    试试……

    CGRect newRect = _webView.bounds;
    newRect.origin.y += 10;
    _webView.bounds = newRect;
    

    【讨论】:

    • 这似乎是在移动整个 UIWebView,而不是滚动它上面的内容,这是我打算做的。可以这样做吗?
    • 我相信您必须将 CGRect 作为一个整体来获取和设置,而不仅仅是 CGPoint 部分。所以我得到了整个矩形,只改变了值并将其设置为一个整体。如果这有意义的话。
    • 是的,您可能需要查看操纵 webview 的“contentOffset”而不是实际的 webview 边界。不完全确定,因为我以前从来没有这样做过 - 但我想它使用滚动视图来显示它的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    相关资源
    最近更新 更多