Tag: 快速

应该使用什么方法dynamic更改所选UICollectionViewCell的大小?

我需要做的是扩大所选单元格的宽度,同时缩小未选中单元格的宽度,以便一次显示所有单元格。 我现在拥有的是: func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 30 } func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { return CGSize(width: collectionView.bounds.width / 30, height: collectionView.bounds.height) } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell: UIDateSliderCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UIDateSliderCell return cell } […]

NSOperationQueue内部的NSOperation中的asynchronouscallback从来没有被调用过

我需要链接几个NSOperation s在一个NSOperationQueue做networking调用,然后等待所有完成。 我将所有的NSOperation添加到我的NSOperationQueue ,然后调用operationQueue.waitUntilAllOperationsAreFinished() 。 这是有效的,但是它会无限期地等待,因为NSOperations的callback将操作的状态设置为“已完成”,因此永远不会被调用。 我正在使用以下NSOperation子类: class ConcurrentOperation: NSOperation { enum State: String { case Ready, Executing, Finished private var keyPath: String { return "is" + self.rawValue } } var state: State = State.Ready { willSet (newValue) { self.willChangeValueForKey(newValue.keyPath) self.willChangeValueForKey(self.state.keyPath) } didSet { self.didChangeValueForKey(oldValue.keyPath) self.didChangeValueForKey(self.state.keyPath) } } } extension ConcurrentOperation { override var ready: […]

调用协议方法两次,Swift

我有从UITextFieldDelegate协议使用方法的子类文件 class MyTextField: UITextField, UITextFieldDelegate { . . . override func willMoveToSuperview(newSuperview: UIView?) { super.willMoveToSuperview(newSuperview) self.delegate = self } func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { // some actions return true } } 在我的ViewController类中,我使用input字段与我的子类 class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var field: MyTextFieldMask! override func viewDidLoad() { super.viewDidLoad() // […]

asynchronous获取Swift Xcode

我使用集合视图来显示存储在CoreData中的图像,只有less数几个(大约15),但是当我向下滚动它时,它的接缝是因为我不是asynchronous获取我的数据,是只有15 UIImages可能吗? 所以这里是我的问题,我无法find任何地方的asynchronous获取下降教程,3天我期待。 对不起,如果我没有好好search。 这是从教程中得到的一些东西 let entity = NSEntityDescription.entityForName("Dreams", inManagedObjectContext: contxt) let fetchRequest = NSFetchRequest() fetchRequest.entity = entity let asyncFetch = NSAsynchronousFetchRequest(fetchRequest: fetchRequest) { (result:NSAsynchronousFetchResult!) -> Void in if result.finalResult!.count > 0 { self.dreams = result.finalResult! as [Dream] } NSLog("Done.") } 梦是一个types的数组[梦想],但是当我显示集合视图什么都没有出现这是我以前做过的 let fetchRequest = NSFetchRequest(entityName: "Dreams") if let fetchResults = contxt.executeFetchRequest(fetchRequest, error: nil) as? […]

Swift:影响button点击的UITextfield? 由于animation无法input文字?

我有一个奇怪的问题,我的UIViewanimation和一个UITextfield – 我需要能够点击一个button,让buttonanimation显示一个文本字段,以便用户可以在文本字段中input文本,然后当用户按下再次button,用户交互在文本字段被禁用,并且button移回。 这就是我的意思 – 我已经在一定程度上通过将文本字段放置在button的后面并在开始时将其禁用,然后当单击该button时buttonanimation起来以显示文本字段, 问题是,当用户去编辑文本字段时,button点击正在被触发(或者可能只是animation)。 所以当他们打字的时候,button只是向下移动并覆盖文本框。 这很奇怪,因为我有一个布尔值来设置button是向上还是向下移动的,我不认为这是翻转的,因为通常button在文本区下面移动,这是不应该发生的。 这是我如何做到这一点: @IBAction func enterText(sender: UIButton) { print("time to enter text") if !textOpen { UIView.animateWithDuration(0.5, animations: { self.textBtn.center.y -= self.textBtn.bounds.height }) happenedTxt.userInteractionEnabled = true } else { UIView.animateWithDuration(0.5, animations: { self.textBtn.center.y += self.textBtn.bounds.height }) happenedTxt.userInteractionEnabled = false } textOpen = !textOpen } 当按下button时,如何才能触发button的移动? 为什么文本框会触发animation? 有没有人打电话让button回到原来的位置?

如果正则expression式有效,如何检查Swift?

我正在使用正则expression式来searchtextView。 所有使用简单的string正常工作,但是当我尝试只input一个正则expression式运算符的一部分,我得到一个错误的现金: Error Domain=NSCocoaErrorDomain Code=2048 "The value “\” is invalid." UserInfo={NSInvalidValue=\} 例如,如果我input“\ n”它的作品,但如果我只input“\”(不含引号),我得到崩溃。 我不能做的是find一种方法来检查expression式之前使用它。 我使用这个代码部分基于这个教程和WiktorStribiżew这个答案: extension NSRegularExpression { convenience init?(options: SearchOptions) { let searchString = options.searchString let isCaseSensitive = options.matchCase // set to true let isWholeWords = options.wholeWords // set to false let escapeMetacharacters = options.escapeMetacharacters // set to false // handle case sensitive option […]

自定义控制中心Swift和IOS 9+

朋友我正在使用Swift的ios应用程序,我想在控制中心添加应用程序图标,并在任何网页上用户应该能够select文本或段落,并保存在应用程序中的文本。 我只是需要一个提示或起点,我对IOS有点新,已经build立了3-4个应用程序,但从来没有在控制中心工作,并添加服务,允许从iPhone浏览器复制和保存文本和图像。

父节点旋转期间,SceneKit子节点位置未更改

我试图在SceneKit中重新编码摄像头pipe理。 为此,我使用UIPanGestureRecognizer围绕一个物体(在这种情况下围绕场景的中心)旋转相机。 接下来,我得到不同的比例或长度来确定在相机所在的虚拟球体的轴(X,Y,Z)上添加的angular度(cameraOrbit in code)。 我的问题是,我使用相机的位置来确定在球体上添加的angular度。 但是这个位置是不变的。 当我改变球体旋转时,子节点相机的位置永远不会更新。 那么angular度不会改变。 import SceneKit import UIKit class SceneManager { private let scene: SCNScene private let view: SCNView private let camera: SCNNode private let cameraOrbit: SCNNode private let cameraRadius: Float init(view: SCNView, assetFolder: String, sceneName: String, cameraName: String, backgroundColor: UIColor) { self.view = view self.scene = SCNScene(named: (assetFolder + […]

如何追加数组。 或者我如何将模型转换为nsmuttable数组

在我的应用程序中,我使用alamofire对象映射器来使用MVC结构。 现在我得到一个数组,我适合模型类。 这里是模型类 class OrderDetailSecond: Mappable { var id : Int? var isRxMedicine : Int? var medicineTypeId : String? var name : String? var orderId : String? var price : String? var quentity : Int? var strength : String? required init?(_ map: Map){ } func mapping(map: Map) { id <- map["id"] isRxMedicine <- map["is_rx_medicine"] medicineTypeId […]

SKAction.moveToX重复值更改

我希望能够移动球,每隔20像素移动一次我试过这个球,但是什么也没做,球停留在开始的地方,它不移动到屏幕的尽头,我知道我没有不要把waitForDuration,因为我想检查它是否会移动或不 func spwan() { let ball:SKSpriteNode = SKScene(fileNamed: "Ball")?.childNodeWithName("ball") as! SKSpriteNode ball.removeFromParent() self.addChild(ball) ball.name = "spriteToTrack" ball.zPosition = 0 ball.position = CGPointMake(1950, 1000) var num:CGFloat = ball.position.x let a1 = SKAction.moveToX(num – 20, duration: 10) // i want to get to -50 let a1 = SKAction.moveToX(-50 , duration: 10) let minus = SKAction.runBlock{ num -= […]