[英]Center iCarousel in TableViewCell in Swift
My iCarousel inside a TableView won't move when I modify CGRect position. 修改CGRect位置时,TableView中的iCarousel不会移动。 Here's how the simulator look like: iCarousel centered vertically and all the way to the top 模拟器的外观如下: iCarousel垂直居中居中,一直到顶部
I included the whole code block. 我包括了整个代码块。 I'm a noob and this is my first app. 我是菜鸟,这是我的第一个应用程序。 Apologies. 道歉。
UIViewController code: 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 code: 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
From README on GitHub: 从GitHub上的README :
- (void)reloadData;
This reloads all carousel views from the dataSource and refreshes the carousel display. 这将从dataSource重新加载所有轮播视图,并刷新轮播显示。
I suppose you should reload @IBOutlet var carouselView: iCarousel!
我想您应该重新加载@IBOutlet var carouselView: iCarousel!
at some point to let carouselView rearrange itself. 在某些时候让carouselView重新排列自己。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.