Zoom in to specific coordinates in PDFKit using swift - ios

I am using pdfkit to open pdf file in my app.
I want to zoom in to specific coordinates.
Let say Following is my pdf page and I want to zoom in to specific coordinates when user will click on pencil button.
After clicking on pencil button it should be look like following image.
I've searched a lot but couldn't find any proper solution for that. I don't want to use third party libraries to do that.

I solved this problem by using following code.
let documents = pdfView.document
if let page = documents?.page(at: 0) {
pdfView.scaleFactor = pdfView.scaleFactorForSizeToFit * 2
pdfView.go(to: CGRect(x: 0, y: 0, width: 300, height: 300), on: page)
}
This is the zoom in code to specific coordinates.
There is one more thing that needs attention. You need to turn off
pagination pdfView.usePageViewController(false).

Related

iOS13+ Creating a constant button on top of every screen

I maintain an app SDK that contains a button which should always be displayed on top of all screens in the application, but this functionality broke with iOS 13+ which seems to have changed some internals. The button disappears after changing from the first screen.
// My code that does not work anymore
var applicationWindow: UIWindow? = UIApplication.shared.keyWindow
...
button.frame = CGRect(x: 0, y: 0, width: 94, height: 73)
applicationWindow!.addSubview(button)
I saw similar posts on SOF suggesting code like
UIApplication.shared.windows.first(where: { $0.isKeyWindow })? but it doesn't work for me, and I'm struggling to create and manage a second UIWindow, any code sample would be really appreciated as I'm only a maintainer and I don't work actively on iOS anymore.

How to add a fixed bar on the mapView on iOS

Recently, I have made a simple project which needs to use GoogleMap Api.
I think that my Question is so simple and easy,
but i don't know how to complete it.
Well this is my problem
i want to add a just simple bar on the View.(up 1, bottom 1)
these 2 bars are fixed. and also there is a button(like moving back button) on the bars that i can presse
Except 2 bar position, if i drag/swipe on mapView than change and show the location information.
please check the following image.(This is what i want to make.)
How can i put the bars on the view and let the bars can be seen in the simulator? plz let me know
(i dont upload code cuz it's not the problem about the code, just want to know about the concept of how to insert view(or layer?) like that)
First, let say you have a map view:
let camera = GMSCameraPosition.camera(withLatitude: 11.5449, longitude: 104.8922, zoom: 12)
let map = GMSMapView.map(withFrame: .zero, camera: camera)
map.isMyLocationEnabled = true
self.view = map
Then, you can just add your top and bottom views to the view as normal
let topBar = UIView()
view.addSubview(topBar)
let bottomBar = UIView()
view.addSubview(bottomBar)
And if you want to add other views such as texts and buttons, you can add them as subviews to the topBar or bottomBar view
let button = UIButton()
topBar.addSubview(button)
Noted: to put the views in the exact locations as in the image, you need to specify their locations.
For example:
bottomBar.frame = CGRect(x: 0, y: view.bounds.height - 200, width: view.bounds.width, height: 200)
In storyboard:
I didn't use google maps so here I'm using the default MKMapView as an example.
First, let's say we have a map view covering the entire view controller:
Then for the top bar, let's add a view and give it some constraints:
Now for the back button and the title:
Now, for the bottom bar: first we need a view to hold all the things:
For the texts, we use 4 uilabels, embed them into a stack to make them lined-up. Give some spacing as well to make them look good:
Finally, for the image on the right, we can use uiimageview or uibutton:
Don't forget to add constraints to the stackview and the uiimageview/uibutton

Import Adobe After Effect animation to xcode

I have some trouble importing my animation from Adobe After Effect to Xcode and web.
I have made a character and rigged it with the Duik-plugin. I made the annimation i would like to get into xcode, and rendered it to JSON using bodymovin.
I have an image of the animation here:
Then i take the rendered JSON file and import it into my project. I use the Lottie-ios framework (https://github.com/airbnb/lottie-ios).
In my viewDidLoad() i use this code to show the animation:
let animationView = LOTAnimationView(name: "Velkomst")
animationView.frame = CGRect(x: 0, y: 100, width:
self.view.frame.size.width, height: 250)
view.addsubview(animatedView.contentMode = .scaleAspectFill
animationView.play()
But as you can see below, the result is pretty... Wierd...
I also created a demo file when i rendered the after effect aniation. On the demo-website it is a little closer to the animation. But still not there.
Can anyone tell me what i am doing wrong? Cause i cant figure it out :-(

Is it possible to use custom iOS UI elements like UILabel in augmented reality app

I am wondering if I can use UI elements like UIButton, UILabel in an augmented reality app with ARKit.
If you are also interested in transparency modes for that UIView subclasses try my sample https://github.com/erikhric/ar-menu
You can use different blending modes. I guess .alpha will work for your purposes.
Yes, you can use UIKit elements by adding them to a UIView that's positioned above the view displaying the AR scene (ARSKView or ARSCNView).
If you create a new project in Xcode and select the "Augmented Reality App" template, you can see that the AR content is just a view like any other UIKit view.
What worked best for me
in main.storyboard:
- delete SceneView
- add regular UIView
- add ARKit SceneKit View on top of that
- then you can add buttons, etc.
Yes you can place UI elements on top of the ARSKView or ARSCNView displaying the AR scene:
let scanningPanel = UIImageView()
scanningPanel.backgroundColor = UIColor(white: 0.33, alpha: 0.6)
scanningPanel.layer.masksToBounds = true
scanningPanel.frame = CGRect(x: -2,
y: self.sceneView.frame.height-270,
width: 178,
height: 50)
scanningPanel.layer.cornerRadius = 10
let scanInfo = UILabel(frame: CGRect(x: 8,
y: self.sceneView.frame.height-268,
width: 160,
height: 45))
scanInfo.textAlignment = .left
scanInfo.font = scanInfo.font.withSize(15)
scanInfo.textColor = UIColor.white
scanInfo.text = "SCAN A SURFACE"
Adding:
self.sceneView.addSubview(scanningPanel)
self.sceneView.addSubview(scanInfo)
Removing:
if(scanInfo.isDescendant(of: self.sceneView)) {
scanInfo.removeFromSuperview()
}
You can insert content of any view on a plane in ARKit like this:
let plane = SCNPlane(width: sceneView.bounds.width/3000,
height: sceneView.bounds.height/3000)
plane.firstMaterial?.diffuse.contents = self.anyView`
Gestures and taps are automatically sent to that view.
Try my example.

Unable to open PowerPoint presentation in edit mode powerpoint iPad from iOS application

I am building an iPad application which contains powerpoint presentations. when a user selects a presentation from app, it will opens in PowerPoint iPad Application.
I tried using UIDocumentInteractionController to open the presentation which is stored in the document directory of my application, But it is opening in read only mode . Is it possible to open the presentation in edit mode?
I used the below Swift code to achieve the functionality and it always opening in read only mode.
let newUrlStr = "file:///private/var/mobile/Containers/Shared/AppGroup/FCE54337-6614-4872-AB7F-945073E7F674/File%20Provider%20Storage/Presentation3.pptx"
let newDocUrl = URL(string: newUrlStr)
documentController = UIDocumentInteractionController(url: newDocUrl)
let frame = CGRect(x: 0, y: 0, width: 20, height: 20)
documentController!.presentOpenInMenu(from: frame, in: self.view, animated: true)
Any help appreciated. Thanks in advance.

Resources