swift3

Move view with keyboard using swift 3

眉间皱痕 提交于 2019-12-11 16:37:52
问题 I have an app that has a text field on the lower half of the view and I have a navigation controller bottom of page. How would I go about moving the view upwards while typing so I can see what i'm typing and then moving it back down to its original place when the keyboard disappears? I don't want to move navigation controller 回答1: You have to observe changes in keyboard frame and act accordingly to show your uiview (uitextfield, uitextview etc.) above the keyboard. NotificationCenter Apple

MTKView vertex transparency is not getting picked up in “additive” blending mode

蓝咒 提交于 2019-12-11 16:22:16
问题 I am trying to implement a metal-backed drawing application where brushstrokes are drawn on an MTKView by stamping a textured square repeatedly along a path. I am varying the stamp's color/transparency at the vertex level as the brushstroke is drawn so I can simulate ink effects such as color/transparency fading over time, etc. This seems to work ok when I am using a classic "over" type blending (which does not accumulate value over time), but when I use "additive" blending, vertex

Filtering Arrays Containing Multiple Data Types in Swift3

亡梦爱人 提交于 2019-12-11 16:13:41
问题 I have an array like:- var arrayData : Array<Dictionary<String, [BottleModel]>> = [] Bottle model :- class BottleModel: NSObject { var name : String var price : Int var reviews : Int var category : String var quantity : String var id : String var shopData : ShopModel } I want filtered array where price is > 2000 I tried let searchByInts = arrayData.filter({m in m.price < 200}) but getting below error: Contextual closure type '(Dictionary) -> Bool' expects 1 argument, but 0 were used in

how to display and where to display a pdf file by considering filePath in swift 3?

瘦欲@ 提交于 2019-12-11 15:30:05
问题 I am new to iOS development. In my project i am displaying a exerciseFilePath on tableview. the response is given below. "exerciseId" : 1, "exerciseName" : "Fitness Exercise", "exerciseFilePath" : "\/p\/pdf\/exercise_pdf\/fitness_exercise.pdf" i need to display the pdf in another view on didSelectRowAtIndexpath. i Dont know how to display the pdf and what are steps to be followed to display that pdf. I hope you understand my problem. please help me how I can do this. 回答1: Why don't you use

If cell is touched - move on the another VC [SWIFT]

落花浮王杯 提交于 2019-12-11 15:27:11
问题 If cell is touched - move on the another VC, how can i do it? I tried to do it, but i didn't work. Here is my code override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "transData" { let destination = segue.destination as! WinnerViewController let cell = sender as? UITableViewCell if cell == cell { let indexPath = tableView.indexPath(for: cell!) if indexPath == indexPath { let productName = users[(indexPath?.row)!] destination.winner = productName.name } }

How to pass Float in CMTimeMake's timescale Int32

╄→гoц情女王★ 提交于 2019-12-11 15:20:22
问题 I am working on CMTimeMake in order to add slow and fast motion effect to Video. Where we have to divide by Video scale for Fast effect and multiply by Video scale for Slow effect. Here it is: let videoScaleFactor = Int64(2) // Get the scaled video duration let scaledVideoDuration = (mode == .Faster) ? CMTimeMake(videoAsset.duration.value / videoScaleFactor, videoAsset.duration.timescale) : CMTimeMake(videoAsset.duration.value * videoScaleFactor, videoAsset.duration.timescale) Now as per my

CollectionView Cell dynamic height for all screensizes

狂风中的少年 提交于 2019-12-11 15:19:38
问题 In my project, my collectionview cell comprises of the entire screen width and height, i've set it to horizontal scrolling and for making it dynamic for all screensizes, i am using this method func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let height: CGFloat = view.frame.size.height let width: CGFloat = view.frame.size.width return CGSize(width: collectionView.bounds.size.width,

RLMException “Realm at path ' ' already opened with different encryption key” after writeCopy(toFile:,encryptionKey:)

可紊 提交于 2019-12-11 15:17:30
问题 I'm trying to change encryption key for my Realm database using writeCopy(toFile:, encryptionKey:) , like below: public static func updateEncryption(forNewKey newKey: String, withOldKey oldKey: String, completion: (() -> Void)) { let defaultURL = Backup.realmContainerURL let defaultParentURL = defaultURL.deletingLastPathComponent() let compactedURL = defaultParentURL.appendingPathComponent("default-compact.realm") let oldKeyData = oldKey.pbkdf2SHA256(keyByteCount: 64) let newKeyData = newKey

Gradient not covering full frame SWIFT

随声附和 提交于 2019-12-11 15:16:52
问题 I have the following extension to imageView : extension UIImageView { func addBlackGradientLayer(frame: CGRect){ let gradient = CAGradientLayer() gradient.frame = frame gradient.colors = [UIColor.clear.cgColor, UIColor.black.cgColor] gradient.locations = [0.0, 1.0] self.layer.addSublayer(gradient) }} imageView.addBlackGradientLayer(frame: imageView.frame) on applying this to the imageView, I am having the following output. I tried setting the constraints and also, the autolayout. Following is

Can not fetch data using Alamofire?

时光毁灭记忆、已成空白 提交于 2019-12-11 15:06:44
问题 I am trying to fetch data in my iOS app from my Django backend. In postman if I perform a GET request on the following URL http://127.0.0.1:8000/api/places/categories with the params being Key:"Authorization" Value: "Bearer access_token". I get a JSON response. Inside my app I am doing something like this with the help of Alamofire: let access_token = "123" let headers = ["Authorization": "Bearer" + access_token] Alamofire.request(self.categoriesUrl, method: .get, parameters:nil,encoding: