我們有Xcode的8.2.1 SWIFT 2.3項目錯誤。 我汽車從2.3迅速轉換3。我當從2.3迅速轉換3「不能調用初始化類型‘CGFloat的’類型的參數列表「((UIContentContainer,C ~~
但是我有兩個麻煩。
1.Cannot invoke initializer for type 'CGFloat' with an argument list of type '((UIContentContainer, CGSize) -> CGSize)'
2.Binary operator '+' cannot be applied to operands of type '(UIContentContainer, CGSize) -> CGSize' and 'CGFloat'
// GENERATE A GRID FOR BLOCKS -----------------------
for i in 1...gridSize {
for j in 1...gridSize {
let _j = CGFloat(j-1)
let _a = (view.frame.width - CGFloat(gridSize))
let _b = (CGFloat(size) + CGFloat(padding))
let _ab = (_a * _b)/2
let _c = _j * (size + padding)
let _abc = _ab + _c
//let _x = (view.frame.width - CGFloat(gridSize) * (CGFloat(size) + CGFloat(padding)))/2 + _j * (size + padding)
let _x = _abc
let _y = CGFloat(rectsHeight) + CGFloat(i-1) * (size + padding)
let r = Rectangle(type: "default", x: _x, y: _y, size: size, color: midGray, view: gameView!,real_x : _x, real_y : _y)
rectanglesArray.append(r)
}
}
這是一個錯誤的消息最終產品的代碼。 讓大小和填充是CGFloat的。
爲什麼不能給做計算(CGFloat(size)+ CGFloat(padding))? 我們從Swift 2.3開始工作。 但無法使用Swift 3.
請支持我所有。
謝謝。
--04 /二千零十七分之二十二11時54 Added-- お返事をありがとうございます。
對不起,我忘記細節填充。
// Resize views accodingly to device screen size
if UIScreen.main.bounds.size.width == 320 {
//iPhone 4/5
var size: CGFloat = 25
blocksHeight = 380
afterTouchSizeOffset = 23
} else if UIScreen.main.bounds.size.width == 375 {
// iPhone 6
var size: CGFloat = 33
var padding: CGFloat = 3
blocksHeight = 520
afterTouchSizeOffset = 28
} else if UIScreen.main.bounds.size.width == 414 {
// iPhone 6+
var size: CGFloat = 36
var padding: CGFloat = 4
blocksHeight = 570
afterTouchSizeOffset = 33
} else if UIScreen.main.bounds.size.width == 768 {
// iPad
var size: CGFloat = 55
var padding: CGFloat = 6
blocksHeight = 830
afterTouchSizeOffset = 50
}
我們檢查了所有的定義填充。
Config.swift
/*** DO NOT EDIT THE VARIABLES BELOW ***/
var soundURL: URL?
var soundID:SystemSoundID = 0
var padding:CGFloat = 2
var size:CGFloat = 28
let gridSize = 10
var gameView:UIView?
var score = 0
var bestScore = Int()
var lastScore = Int()
var playCount = Int()
var gameEnded = false
var bounds = CGRect()
改變的代碼。 但是,新的錯誤...
3.Cannot分配給屬性: '尺寸' 是一種方法
// Resize views accodingly to device screen size
if UIScreen.main.bounds.size.width == 320 {
//iPhone 4/5
size = 25
blocksHeight = 380
afterTouchSizeOffset = 23
} else if UIScreen.main.bounds.size.width == 375 {
// iPhone 6
size = 33
padding = 3
blocksHeight = 520
afterTouchSizeOffset = 28
} else if UIScreen.main.bounds.size.width == 414 {
// iPhone 6+
size = 36
padding = 4
blocksHeight = 570
afterTouchSizeOffset = 33
} else if UIScreen.main.bounds.size.width == 768 {
// iPad
size = 55
padding = 6
blocksHeight = 830
afterTouchSizeOffset = 50
}
---- -----解決
Config.swift
Befor
/*** DO NOT EDIT THE VARIABLES BELOW ***/
var soundURL: URL?
var soundID:SystemSoundID = 0
var padding:CGFloat = 2
var size:CGFloat = 28
後
/*** DO NOT EDIT THE VARIABLES BELOW ***/
var soundURL: URL?
var soundID:SystemSoundID = 0
GameBoard.swift
Befor
// Dimension variables
var rectsHeight = 50
var blocksHeight = 435
var rectsForDissapear = Array<Dictionary<String,Any>>()
var gridTilesAmount = Array<Int>()
var blockEndCoords : CGPoint = CGPoint()
var afterTouchSizeOffset : CGFloat = 25
var selectedBlock : Block?
var startTouchCoords : CGPoint = CGPoint()
let DeviceTest:Bool = false
let SimulatorTest:Bool = true
後
// Dimension variables
var rectsHeight = 50
var blocksHeight = 435
var rectsForDissapear = Array<Dictionary<String,Any>>()
var gridTilesAmount = Array<Int>()
var blockEndCoords : CGPoint = CGPoint()
var afterTouchSizeOffset : CGFloat = 25
var selectedBlock : Block?
var startTouchCoords : CGPoint = CGPoint()
let DeviceTest:Bool = false
let SimulatorTest:Bool = true
var padding:CGFloat = 2
var size:CGFloat = 28
感謝所有支持者。
感謝您的回覆。 添加了詳細信息。 我爲填充設置了數字。 爲什麼編譯器認爲是閉包? 我很困惑... – Yuki
不要再回頭了 我們有一個Configs.swift。 我們定義該文件。 /***不要編輯下面的變量***/ var soundURL:URL? VAR soundID:SystemSoundID = 0 VAR填充:CGFloat的= 2 變種尺寸:CGFloat的= 28 讓gridSize = 10 變種gameView:UIView的? VAR得分= 0 VAR bestScore = INT() VAR lastScore = INT() VAR playCount = INT() VAR gameEnded =假 VAR邊界=的CGRect() – Yuki
謝謝! '// accodingly調整視圖設備屏幕大小 如果UIScreen.main.bounds.size.width == 320 { // iPhone五分之四 大小= 25 blocksHeight = 380 afterTouchSizeOffset = 23 }。 ..... – Yuki