我有两个观点,我想做一个轻扫样式转换,我已经完成了当有一个segue行动,但我没有在这里,所以我不知道如何应用我的动画类.我班上的所有内容都是:
let stb = UIStoryboard(name: "Walkthrough", bundle: nil)
let walkthrough = stb.instantiateViewControllerWithIdentifier("walk") as! BWWalkthroughViewController
self.presentViewController(walkthrough, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我想申请申请以下自定义segue:
class CustomSegue: UIStoryboardSegue {
override func perform() {
// Assign the source and destination views to local variables.
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!
// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight) …Run Code Online (Sandbox Code Playgroud) 我有一个Bools数组,想要编辑一个Scores数组和一个Dates数组,其值为False.我无法理解.我想到了获取false的元素并使用该数组从score数组中删除这些元素,但我可以想象有一种直接的方法.
let hbiCompleteArray = [true, true, true, true, false, true, true, false, false]
let hbiScoreArray = [12, 12, 12, 12, 3, 13, 13, 2, 2]
Run Code Online (Sandbox Code Playgroud)
我想要一个完整的HbiScores数组= [12,12,12,12,13,13]
我有一个疼痛贴图,我使用位置坐标来绘制疼痛的位置.我可以在for循环中添加"点",它们显示正常.但是,在我在for循环之外实例化它们之前,我无法删除它们.因此,每次我更新视图时,它都会绘制新视图而不是旧视图.我能做什么?
这个版本添加了很好的点,但我不能删除它们,因为我不能调用dot.removeFromSuperview()
DispatchQueue.global(qos: .background).async {
if let locationNotNilX = self.painDiagramAnalysisModel.painLocationXFor(days: self.daysChosen){
x = locationNotNilX
count = locationNotNilX.count
}
if let locationNotNilY = self.painDiagramAnalysisModel.painLocationYFor(days: self.daysChosen){
y = locationNotNilY
}
let locationsArray = zip(x, y)
print("zipped array \(locationsArray)")
DispatchQueue.main.async {
let dot = UIImageView()
dot.removeFromSuperview()
dot.image = nil
for item in locationsArray {
self.locationPainY = (diagramHeight * CGFloat(item.1)) + originY
self.locationPainX = (diagramWidth * CGFloat(item.0)) + originX
print(" locationX \(self.locationPainX) locationY \(self.locationPainY)")
dot.image = UIImage(named: "dot")
dot.frame = CGRect(x: self.locationPainX - (dotDiameter …Run Code Online (Sandbox Code Playgroud) 我有一个变化的数组,我想找到一个元素的出现次数,但表示为百分比,例如:
var filteredArray = [1,2,4,5,2,1,2,1,5,5]
var counts:[Int: Int] = [:]
for item in zeroRemovedArray2 {
counts[item] = (counts[item] ?? 0) + 1
}
Run Code Online (Sandbox Code Playgroud)
这给出了事件[1:3,2:3,3:0,4:1,5:3],但我希望有一个字典[1:0.3,2:0.3,3:0,4:0.1, 5:0.3]
我可以看到在某个循环中使用每个值的/.count但是无法弄明白.