为啥浏览器访问空间时横向滚动条没了

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为啥浏览器访问空间时横向滚动条没了相关的知识,希望对你有一定的参考价值。

因为当前页面已经显示了所有内容,而只有当前页面大小无法显示所有内容是才会出现上下或者横向的滚动条 参考技术A 看看你用的是IE浏览器还是其他的比如世界之窗这样的 如果是世界之窗右下角有一个百分比那个 你调那个 可以解决

为啥当我滚动浏览 UITableView 时图像会不断调整大小?

【中文标题】为啥当我滚动浏览 UITableView 时图像会不断调整大小?【英文标题】:Why do the images keep on resizing as I scroll through my UITableView?为什么当我滚动浏览 UITableView 时图像会不断调整大小? 【发布时间】:2018-01-13 05:56:58 【问题描述】:

所有图像都可以正常加载并显示其宽度与手机相同,其高度由照片的纵横比决定。最初除了第三张照片之外的所有照片都以这种方式加载,在滚动出图像视图并返回后,图像会正确调整大小,但最初图像只是在 scaleaspectFill 中,没有正确的宽度和高度。

import UIKit
import Firebase
import FirebaseStorageUI

class TableViewController: UITableViewController 
var images:[UIImage]! = [#imageLiteral(resourceName: "rininger_2.jpg")]
var imageURLS:[String] = [String]()
var listener:ListenerRegistration?

override func viewDidLoad() 
    super.viewDidLoad()

    /////////
    listener = Firestore.firestore().collection("Posts").addSnapshotListener
        querySnapshot, error in
        guard let snapshot = querySnapshot else 
            print("Error fetching snapshots: \(error!)")
            return
        
        snapshot.documentChanges.forEach  diff in
            if (diff.type == .added) 
                print("New data: \(diff.document.data())")
            
            if (diff.type == .modified) 
                print("Modified city: \(diff.document.data())")
            
            if (diff.type == .removed) 
                print("Removed city: \(diff.document.data())")
            
            // self.numberOfRows = snapshot.count
            // Parse each post


            //self.labels.append(newLabel)


            //Update TableView
            DispatchQueue.main.async 
                //This would reload everything creating a flash
                //self.tableView.reloadData()
                guard let newImageURL = diff.document.data()["imageDownloadURL"] as? String else
                    print("Failed to get image download URL")
                    return
                
                //let newLabel = Post(snapshot:diff.document)
                print("downloadURL: \(newImageURL)")
                self.imageURLS.insert(newImageURL, at: 0)
                let indexPath = IndexPath(row: 0, section: 0)
                self.tableView.insertRows(at: [indexPath], with: .top)

            
        
    /////////
    



override func didReceiveMemoryWarning() 
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.


// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int 
    // #warning Incomplete implementation, return the number of sections
    return 1


override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    // #warning Incomplete implementation, return the number of rows
    return imageURLS.count



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Reuse", for: indexPath) as! TableViewCell

    // Configure the cell...

    ///////////////////////
        let downloadURL = URL(string: imageURLS[indexPath.row])

            //cell.cellImageView.sd_setImage(with: downloadURL, completed:nil)
            //cell.cellImageView.image = self.images[indexPath.row]
    do
        let imageData = try Data(contentsOf: URL(string:(imageURLS[indexPath.row]))!)
        cell.cellImageView.image = UIImage(data: imageData)
    
    catch
        print("unable to load data: \(error)")
    
            cell.cellImageView.contentMode = .scaleAspectFit
            let aspectRatio = Float((cell.cellImageView?.image?.size.width)!/(cell.cellImageView?.image?.size.height)!)
            tableView.rowHeight = CGFloat(Float(UIScreen.main.bounds.width)/aspectRatio)

    ///////////////////////
    return cell
 

【问题讨论】:

【参考方案1】:

确保UIImageView 上的clipsToBounds 属性设置为true

【讨论】:

感谢您的回复,不幸的是它不是那么简单,我已尝试将约束设置为对所有范围都归零。我相信它与队列有关。

以上是关于为啥浏览器访问空间时横向滚动条没了的主要内容,如果未能解决你的问题,请参考以下文章

C# winfom 中如何设置listview空间只有竖直方向的滚动条,不要横向的滚动条呢?如图,去掉横向的。

IE6下出现横向滚动条问题的解决方案

elementui表格横向滚动条随浏览器大小变化

html网页中图片横向滚动

css Div在页面中纵向固定,不随滚动条滚动,横向随滚动条滚动

这是控制浏览器的横向滚动条居中的代码,可是不兼容火狐,高手帮忙改改..