Tag: 迅速

如何使用AVCapturePhotoOutput

我一直在使用一个自定义的相机,我最近升级到Xcode 8 beta与斯威夫特3我原本有这样的: var stillImageOutput: AVCaptureStillImageOutput? 但是,我现在得到警告: 在iOS 10.0中不推荐使用“AVCaptureStillImageOutput”:使用AVCapturePhotoOutput 由于这是相当新的,我没有看到这方面的很多信息。 这是我现在的代码: var captureSession: AVCaptureSession? var stillImageOutput: AVCaptureStillImageOutput? var previewLayer: AVCaptureVideoPreviewLayer? func clickPicture() { if let videoConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo) { videoConnection.videoOrientation = .portrait stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (sampleBuffer, error) -> Void in if sampleBuffer != nil { let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) let dataProvider = CGDataProvider(data: […]

如何获得AFNetworking 2.0的下载进度?

我正在使用AFURLSessionManager来创build一个新的下载任务: AFURLSessionManager* manager = … NSProgress* p = nil; NSURLSessionDownloadTask* downloadTask = [manager downloadTaskWithRequest:request progress:&p destination:^NSURL*(NSURL* targetPath, NSURLResponse* response) {…} completionHandler:^(NSURLResponse* response, NSURL* filePath, NSError* error) {…} ]; [downloadTask resume]; 该文件得到下载罚款,但是,我怎么得到进展通知? p总是设为零。 我为此提出了一个问题 。 我也尝试在pipe理器上调用setDownloadTaskDidWriteDataBlock ,并在那里获取进度通知,但是在文件下载完成后 ,我将它们全部分组。 看起来这个区域在AFNetworking 2.0中还是有点bug的 有任何想法吗?

如何在Swift中调整图像大小?

我正在使用Swift和Parse.com为iOS创build一个应用程序 我试图让用户从图像select器中select一张图片,然后在上传到我的后端之前将所选图像的大小调整为200×200像素。 Parse.com有一个名为“AnyPic”的Instagram复制应用程序的教程,它给出了调整图像大小的代码,但它在Objective-C中。 // Resize the image to be square (what is shown in the preview) UIImage *resizedImage = [anImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(560.0f, 560.0f) interpolationQuality:kCGInterpolationHigh]; // Create a thumbnail and add a corner radius for use in table views UIImage *thumbnailImage = [anImage thumbnailImage:86.0f transparentBorder:0.0f cornerRadius:10.0f interpolationQuality:kCGInterpolationDefault]; 如何在Swift中创build200x200px的选定图片(然后上传)? 而且,thumbnailImage函数在做什么?

在UITextField的开头创build空格

我想在UITextField的开头留下一些空格,就像这样: 将左边距添加到UITextField 但是我不知道如何用Swift做到这一点。

如何在Swift中用XIB文件初始化/实例化一个自定义的UIView类

我有一个名为MyClass的类,它是UIView的子类,我想用XIB文件初始化。 我不知道如何使用名为View.xib的xib文件来初始化这个类 class MyClass: UIView { // what should I do here? //init(coder aDecoder: NSCoder) {} ?? }

在swift中捕获无效用户input的exception

我正在尝试这是一个计算器的代码。 我如何处理无效的用户input? //解答:将头部桥接到Objective-C // https://github.com/kongtomorrow/TryCatchFinally-Swift 这是同样的问题,但在objc,但我想迅速做到这一点。 捕获NSExpression中的NSInvalidArgumentException 所有我想要显示的是一个消息,如果它不起作用,但现在我得到一个exception,当用户没有input正确的格式。 import Foundation var equation:NSString = "60****2" // This gives a NSInvalidArgumentException', let expr = NSExpression(format: equation) // reason: 'Unable to parse the format string if let result = expr.expressionValueWithObject(nil, context: nil) as? NSNumber { let x = result.doubleValue println(x) } else { println("failed") }

swift:将string转换为double的问题

这是Xcode 7.3.1操作系统中的一个简单代码: var str = "8.7" print(Double(str)) 输出是惊喜: Optional(8.6999999999999993) 另外, Float(str)给出: 8.69999981 任何想法或这个家伙的原因? 任何提及这个将不胜感激。 另外,我应该如何将“8.7”​​转换为双倍(或浮动)8.7? 编辑 在迅速: (str为NSString).doubleValue返回8.7 现在,这是好的。 但是我的问题仍然没有得到完整的答案。 我们已经find了一个select,但为什么我们不能依靠双(“8.7”​​)。 请对此进行更深入的了解。 编辑2 (NSString为“6.9”).doubleValue //打印6.9000000000000004 所以,这个问题再次打开。

在Swift中将hexstring转换为NSData

我得到了在Objective-C中将string转换为HEX-String的代码。 – (NSString *) CreateDataWithHexString:(NSString*)inputString { NSUInteger inLength = [inputString length]; unichar *inCharacters = alloca(sizeof(unichar) * inLength); [inputString getCharacters:inCharacters range:NSMakeRange(0, inLength)]; UInt8 *outBytes = malloc(sizeof(UInt8) * ((inLength / 2) + 1)); NSInteger i, o = 0; UInt8 outByte = 0; for (i = 0; i < inLength; i++) { UInt8 c = inCharacters[i]; SInt8 value […]

按数字字母顺序排列数组

myArray = [Step 6, Step 12, Step 5, Step 14, Step 4, Step 11, Step 16, Step 9, Step 3, Step 13, Step 8, Step 2, Step 10, Step 7, Step 1, Step 15] 我怎样才能以这种方式排列这个数组? [Step 1, Step 2, Step 3, Step 4, ….] 我在swift中使用了这个函数sort(&myArray,{ $0 < $1 })但是这样sorting [Step 1, Step 10, Step 11, […]

如何在Swift中使用NSURLSessionDataTask

有人能帮我吗? 我无法find完成语法的一个很好的例子。 var url : NSURL = NSURL.URLWithString("https://itunes.apple.com/search?term=\(searchTerm)&media=software") var request: NSURLRequest = NSURLRequest(URL:url) let config = NSURLSessionConfiguration.defaultSessionConfiguration() let session = NSURLSession.sessionWithConfiguration(config) NSURLSessionDataTask(session.dataTaskWithRequest(request, completionHandler: ((NSData!, NSURLResponse!, NSError!) -> Void)?) 谢谢!