我想加入UICollectionView到ViewController了,我需要有"每行" 3个细胞无细胞之间的空格(它应该看起来像一个网格).单元格宽度应该是屏幕尺寸的三分之一,所以我认为layout.item宽度应该相同.但后来我明白了:

如果我减小那个尺寸(例如7或8像素),那就更好了,但是行中的第三个单元格不是完全可见的,我仍然有那个空白区域(顶部和底部,左侧和右侧).

class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
var collectionView: UICollectionView?
var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!
override func viewDidLoad() {
super.viewDidLoad()
screenSize = UIScreen.mainScreen().bounds
screenWidth = screenSize.width
screenHeight = screenSize.height
// Do any additional setup after loading the view, typically from a nib
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
layout.itemSize = CGSize(width: screenWidth / 3, height: …Run Code Online (Sandbox Code Playgroud) uicollectionview uicollectionviewcell uicollectionviewlayout swift
有没有办法在现在(孩子)获得父VC的班级名称UIViewController?我的'孩子'VC(推)有两个'父母' UIViewController,所以我想知道哪一个是现在的父母?
我在我的iPhone应用程序中有简单的AVAudioPlayer,它可以工作,但输出应该是手机扬声器而不是耳机.我在这里找到了类似的主题,但不知道如何将其"翻译"为swift(AudioSessionSetProperty令我困惑)?
var audioPlayer = AVAudioPlayer(data: fileData, error: &playbackError)
//fileData is url to file
if let player = audioPlayer{
player.delegate = self
if(player.prepareToPlay() && player.play()){
println("Started playing the recorded audio")
} else {
println("Could not play the audio")
}
}
Run Code Online (Sandbox Code Playgroud)