【问题标题】:Center iCarousel in TableViewCell in Swift在 Swift 中的 TableViewCell 中居中 iCarousel
【发布时间】:2019-01-23 08:44:49
【问题描述】:

当我修改 CGRect 位置时,TableView 中的 iCarousel 不会移动。下面是模拟器的样子:iCarousel centered vertically and all the way to the top

我包含了整个代码块。我是菜鸟,这是我的第一个应用程序。道歉。

UIViewController 代码:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}


var gameTitles = ["Game Title 1", "Game Title 2", "Game Title 3", "Game Title 4", "Game Title 5" ]
// Place Holders for game titles

func numberOfSections(in tableView: UITableView) -> Int {
    return gameTitles.count
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    let screenHeight = UIScreen.main.fixedCoordinateSpace.bounds.height - 113
    tableView.rowHeight = screenHeight
    return gameTitles[section]
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CarouselView
    return cell
}

UITableViewCell 代码:

import UIKit

class CarouselView : UITableViewCell, iCarouselDelegate, iCarouselDataSource {

@IBOutlet var carouselView: iCarousel!
var gameImages = [1,2,3,4,5,6,7,8,9,10]

override func awakeFromNib() {
    carouselView.type = .coverFlow2

}

func numberOfItems(in carousel: iCarousel) -> Int {
    return gameImages.count
}

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
    let cellWidth = UIScreen.main.bounds.size.width - 40
    let logView = UIView(frame: CGRect(x: 0, y: 0, width: cellWidth, height: cellWidth))
    logView.backgroundColor = UIColor.red
    logView.layer.borderColor = UIColor.black.cgColor
    logView.layer.borderWidth = 3.0
    return logView
}

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    if option == iCarouselOption.spacing{
        return value * 1.1
    } 
    return value

【问题讨论】:

    标签: ios swift xcode9.3


    【解决方案1】:

    来自 GitHub 上的README

    - (void)reloadData;
    

    这会从数据源重新加载所有轮播视图并刷新轮播显示。

    我想你应该重新加载 @IBOutlet var carouselView: iCarousel! 在某个时候让 carouselView 重新排列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多