Tag: 迅速

将UTCdate格式转换为本地nsdate

我从我的服务器获取UTC时区的stringdate,我需要将其转换为本地时区。 我的代码: let utcTime = "2015-04-01T11:42:00.269Z" let dateFormatter = NSDateFormatter() dateFormatter.timeZone = NSTimeZone(name: "UTC") dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" let date = dateFormatter.dateFromString(utcTime) println("utc: \(utcTime), date: \(date)") 这打印 – utc:2015-04-01T11:42:00.269Z,date:可选(2015-04-01 11:42:00 +0000) 如果我删除 dateFormatter.timeZone = NSTimeZone(name: "UTC") 它打印 utc:2015-04-01T11:42:00.269Z,date:可选(2015-04-01 08:42:00 +0000) 我的本地时区是UTC +3,在第一个选项我得到UTC在第二个选项我得到UTC -3 我应该得到 utc:2015-04-01T11:42:00.269Z,date:可选(2015-04-01 14:42:00 +0000) 那么如何将UTCdate格式转换为当地时间呢?

与XIB Swift的UITableViewCell子类

我有一个UITableViewCell子类NameInput ,通过一个自定义的init方法连接到一个xib。 class NameInput: UITableViewCell { class func make(label: String, placeholder: String) -> NameInput { let input = NSBundle.mainBundle().loadNibNamed("NameInput", owner: nil, options: nil)[0] as NameInput input.label.text = label input.valueField.placeholder = placeholder input.valueField.autocapitalizationType = .Words return input } } 有没有办法可以在viewDidLoad方法中初始化这个单元格,并仍然可以重用它? 还是必须使用重用标识符注册类本身?

如何使用YouTube API V3?

我试图找出如何在我的iOS应用程序中使用新的YouTube API(版本3),但我不知道该怎么做。 我做了很多研究,但是我发现所有的旧API的例子和代码,所以他们是无效的。 直到现在我明白,要使用新的API,你必须在Google开发者控制台中创build一个项目(而且我这么做了)…但是,然后他们发送给你一个页面,上面有一些代码,但我真的不明白如何使用它。 链接到谷歌API页面我需要知道的是如何从YouTubevideo的给定url检索一些信息,我需要的信息是“喜欢”的总数和“视图”的总数…与API 2它是非常简单的做…但现在我真的不知道从哪里开始…请问有人可以解释如何实现这个也许一些例子和一些代码? 我很确定很多人会从中受益。

如何在CALayer上进行转换?

在写这个问题之前,我已经 有Affine转换观点的经验 阅读Quartz 2D Programming Guide中的Transforms文档 看到这个详细的CALayer教程 从Github下载并运行LayerPlayer项目 不过,我仍然无法理解如何在图层上进行基本的变换。 寻找翻译,旋转和缩放的解释和简单的例子已经很困难。 今天,我终于决定坐下来,做一个testing项目,并把它们弄清楚。 我的答案在下面。 笔记: 我只做Swift,但如果别人想要添加Objective-C代码,请成为我的客人。 在这一点上,我只关心理解二维变换。

标签栏上的自定义button变圆

这是我正在做的事情: 注意:截图取自iOS的早期版本 我所能达到的: 码: override func viewWillAppear(animated: Bool) { // Creates image of the Button let imageCameraButton: UIImage! = UIImage(named: "cameraIcon") // Creates a Button let cameraButton = UIButton(type: .Custom) // Sets width and height to the Button cameraButton.frame = CGRectMake(0.0, 0.0, imageCameraButton.size.width, imageCameraButton.size.height); // Sets image to the Button cameraButton.setBackgroundImage(imageCameraButton, forState: .Normal) // Sets […]

IOSvideo压缩Swift iOS 8损坏的video文件

我试图压缩来自UIImagePickerController(不是现有的video,而是一个dynamic的)用户相机拍摄的video上传到我的服务器,需要一点时间这样做,所以更小的尺寸是理想的,而不是30- 45 mb在较新的质量相机。 这里是在iOS 8中快速执行压缩的代码,它压缩得非常好,我轻松地从35毫秒降低到2.1毫秒。 func convertVideo(inputUrl: NSURL, outputURL: NSURL) { //setup video writer var videoAsset = AVURLAsset(URL: inputUrl, options: nil) as AVAsset var videoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0] as AVAssetTrack var videoSize = videoTrack.naturalSize var videoWriterCompressionSettings = Dictionary(dictionaryLiteral:(AVVideoAverageBitRateKey,NSNumber(integer:960000))) var videoWriterSettings = Dictionary(dictionaryLiteral:(AVVideoCodecKey,AVVideoCodecH264), (AVVideoCompressionPropertiesKey,videoWriterCompressionSettings), (AVVideoWidthKey,videoSize.width), (AVVideoHeightKey,videoSize.height)) var videoWriterInput = AVAssetWriterInput(mediaType: AVMediaTypeVideo, outputSettings: videoWriterSettings) videoWriterInput.expectsMediaDataInRealTime = true videoWriterInput.transform […]

iOS推送通知:如何检测当应用程序在后台时用户是否轻敲通知?

有很多关于这个主题的stackoverflow线程,但我仍然没有find一个好的解决scheme。 如果应用程序不在后台,我可以在application:didFinishLaunchingWithOptions:检查launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] application:didFinishLaunchingWithOptions:调用以查看是否从通知打开。 如果应用程序在后台,所有postbuild议使用application:didReceiveRemoteNotification:并检查应用程序状态。 但是,正如我试验(也作为这个API的名称build议),这个方法被调用时收到的通知,而不是轻拍。 所以问题是,如果应用程序启动,然后后台,你知道从application:didReceiveNotification接收通知application:didReceiveNotification ( application:didFinishLaunchWithOptions:不会触发),你怎么知道用户是否恢复从应用程序点击通知或只是点击应用程序图标? 因为如果用户点击通知,则期望打开通知中提到的页面。 否则它不应该。 我可以使用handleActionWithIdentifier进行自定义动作通知,但是只有当自定义动作button被触发时才触发,而不是在用户点击通知主体时触发。 谢谢。 编辑: 在阅读下面的一个答案后,我想这样可以澄清我的问题: 我们如何区分这两种情况: (A)1.app进入后台; 收到通知 3.用户点击通知; 4.应用程序进入前台 (B)1.app进入背景; 收到通知 3.用户稍后忽略通知并点击应用程序图标; 4.应用程序进入前台 由于application:didReceiveRemoteNotification:在步骤2中都触发了这两种情况。 或者, application:didReceiveRemoteNotification:仅在步骤3中触发(A),但我以某种方式configuration了我的应用程序错误,所以我在步骤2看到它?

在Swift中设置多次通知

所以我现在正在使用Swift,并且当一个开关被激活时,我有一个通知出现在某个时间。 不过,我希望在另一个开关被激活的时候再次发出另一个通知。 这是我的代码为ViewController: @IBOutlet var myDatePicker: UIDatePicker! @IBOutlet var mySwitch: UISwitch! @IBOutlet var mySwitchTwo: UISwitch! var localNotification:UILocalNotification = UILocalNotification() var localNotificationTwo:UILocalNotification = UILocalNotification() func datePicker() { myDatePicker.datePickerMode = UIDatePickerMode.Date } func datePickerDefaultDate() { myDatePicker.date = NSDate().xDays(+1) } func toggleSwitch(){ if mySwitch.on{ localNotification.alertAction = "Open App" localNotification.alertBody = "Please take your medication." localNotification.fireDate = myDatePicker.date.fireDate localNotification.repeatInterval […]

不能保存tmp目录内的文件

我有这个function来保存tmp文件夹内的图像 private func saveImageToTempFolder(image: UIImage, withName name: String) { if let data = UIImageJPEGRepresentation(image, 1) { let tempDirectoryURL = NSURL.fileURLWithPath(NSTemporaryDirectory(), isDirectory: true) let targetURL = tempDirectoryURL.URLByAppendingPathComponent("\(name).jpg").absoluteString print("target: \(targetURL)") data.writeToFile(targetURL, atomically: true) } } 但是,当我打开我的应用程序的临时文件夹,它是空的。 我在做什么错误将图像保存在临时文件夹?

添加模态popup到地图注释 – Swift 3.0

我在地图上有一些自定义的引脚,当用户点击一个引脚,然后在Callout View上的button,我会添加一个function,使用场景基座启动Modal Popup 这是我的代码: func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { // here I would like to launch a Modal Popup using Scene Dock popInfo.center = view.center popInfo.transform = CGAffineTransform(scaleX: 0.8, y: 1.2) self.view.addSubview(popInfo) UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: { self.dimView.alpha = 0.8 self.popInfo.transform = […]