小编san*_*t05的帖子

解散UIImagePickerController也会解散呈现视图控制器

我正在开发一个使用tabbar系统的项目.tabbar项目之一是JobPostingViewController.我将它嵌入UINavigationController中.在这个视图控制器中有一个名为add new job的UIButton.我实现了pushviewcontroller去CreateJobPostViewController.在那里我需要添加UIImagePickerController来选择图像.当我点击完成按钮或从库中选择一个图像时,它会关闭到JobPostingViewController.但它应该去CreateJobPostViewController.任何人请帮助我.提前致谢.

你可以在这里看到问题:
在此输入图像描述

JobPostingViewController中的代码

 @IBAction func openCreateJob(sender: AnyObject) {
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("CreateJobPostViewController") as! CreateJobPostViewController
    self.navigationController?.pushViewController(vc, animated: true)
}
Run Code Online (Sandbox Code Playgroud)

CreateJobPostViewController中的代码

   @IBAction func addImages(sender: AnyObject) {
    imagePicker.allowsEditing = false
    imagePicker.sourceType = .PhotoLibrary
    presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    picker.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    picker.dismissViewControllerAnimated(true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiimagepickercontroller ios swift

9
推荐指数
3
解决办法
5133
查看次数

如何在 Swift 中将图像转换为渐进式 JPEG?

在我的项目中,我需要将任何格式的图像转换为渐进式 JPEG。我怎样才能做到这一点?

我尝试这样但它不起作用。

let sourceImage = UIImage(named: "example.jpg")
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
let url = CFURLCreateWithString(kCFAllocatorDefault,paths.stringByAppendingPathComponent("progressive.jpg") as CFString  , nil)
let destinationRef = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, nil)
let jfifProperties = NSDictionary(dictionary: [kCGImagePropertyJFIFIsProgressive:kCFBooleanTrue])
let properties = NSDictionary(dictionary: [kCGImageDestinationLossyCompressionQuality:0.6,kCGImagePropertyJFIFDictionary:jfifProperties])
CGImageDestinationAddImage(destinationRef!, (sourceImage?.CGImage)!, properties)
CGImageDestinationFinalize(destinationRef!)
Run Code Online (Sandbox Code Playgroud)

core-graphics image-processing core-image ios swift

6
推荐指数
1
解决办法
981
查看次数

如何使用 Firebase 在 IOS 上实现服务器发送事件?

我正在尝试使用rest api 监听firebase 事件。问题是未调用回调方法。我正在使用EventSource来实现此目的。这是侦听事件的正确方法吗?

Auth.auth().currentUser?.getIDTokenForcingRefresh(true, completion: { (token, error) in
    let server : String =  "https://project-XXXXX.firebaseio.com/.json?auth=\(token!)"

    let eventSource: EventSource = EventSource(url: server)
    eventSource.onOpen {
        // When opened
        debugPrint("eventSource open")
    }

    eventSource.onError { (error) in
        // When errors
        debugPrint("error = \(error?.localizedDescription)")
    }
    eventSource.onMessage { (id, event, data) in
        debugPrint("data = \(data)")
        // Here you get an event without event name!
    }

    eventSource.addEventListener("child_added") { (id, event, data) in
        debugPrint("data = \(data)")
        // Here you get an event 'event-name'
    }
})
Run Code Online (Sandbox Code Playgroud)

ios server-sent-events firebase firebase-realtime-database eventsource

5
推荐指数
1
解决办法
1715
查看次数