iOS SpreadsheetView,旋转时剪切

时间:2017-09-13 16:36:18

标签: ios swift spreadsheet

我有这个问题。我需要像这个截图一样旋转工作表。

enter image description here

所以我用

旋转了UIView(SpreadsheetView类中的子类)
spreadsheetView.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)

并将其设为@IBDesignable,这也是我在故事板中轮换视图的原因。

但是当应用程序启动时,我得到了这个结果:

enter image description here

如您所见,数据被裁剪,并且从未旋转的视图的蓝色边框开始裁剪(参见第一张图像,突出显示的矩形)。 如何以我需要的方向从视图的开头到结尾拟合数据?

我正在使用的库是SpreadsheetView,这是我的班级:

import UIKit
import SpreadsheetView

class TableChartViewController: UIViewController, SpreadsheetViewDataSource {

    var headerString = ["Luogo", "Attività", "Umore", "Tot.", "Alta", "Media", "Bassa"]
    var data = [[String]]()

    @IBOutlet weak var spreadSheetView: SpreadsheetView!

    override func viewDidLoad() {
        super.viewDidLoad()
        spreadSheetView.dataSource = self
        spreadsheetView.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)

        spreadSheetView.register(HeaderCell.self, forCellWithReuseIdentifier: String(describing: HeaderCell.self))
        spreadSheetView.register(TextCell.self, forCellWithReuseIdentifier: String(describing: TextCell.self))
    }

    //sorting funcs
    enum Sorting {
        case ascending
        case descending

        var symbol: String {
            switch self {
            case .ascending:
                return "\u{25B2}" //unicode for black up-pointing triangle
            case .descending:
                return "\u{25BC}" //unicode for black down-pointing triangle
            }
        }
    }
    var sortedColumn = (column: 0, sorting: Sorting.ascending)

    //spreadSheetView funcs
    func numberOfColumns(in spreadsheetView: SpreadsheetView) -> Int {
        return headerString.count
    }

    func numberOfRows(in spreadsheetView: SpreadsheetView) -> Int {
        return 5
    }

    func spreadsheetView(_ spreadsheetView: SpreadsheetView, widthForColumn column: Int) -> CGFloat {
        return 80
    }

    func spreadsheetView(_ spreadsheetView: SpreadsheetView, heightForRow row: Int) -> CGFloat {
        return 40
    }

    func spreadsheetView(_ spreadsheetView: SpreadsheetView, cellForItemAt indexPath: IndexPath) -> Cell? {
        if case 0 = indexPath.row {
            let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: HeaderCell.self), for: indexPath) as! HeaderCell
            cell.label.text = headerString[indexPath.column]

            if case indexPath.column = sortedColumn.column {
                cell.sortArrow.text = sortedColumn.sorting.symbol
            } else {
                cell.sortArrow.text = ""
            }
            cell.setNeedsLayout()

            return cell
        } else {
            let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: TextCell.self), for: indexPath) as! TextCell
            cell.label.text = "Prova"
            return cell
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我找到了一个解决方案,不知道为什么,但它有效!

只需将SpreadsheetView放在另一个UIView的默认课程中,然后旋转 这个。 显然,请务必将SpreadsheetViewUIView的尺寸相匹配,就是这样。

Screen of the app with this workaround