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 :-(
Related
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.
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).
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.
I can't find an updated article that shows how to show a live preview of my UIView animations. Methods like XCShowView() aren't used in Swift anymore, according to the error I received in the playground editor.
Does anyone know how to show the prototyping preview in Playgrounds?
This works in Xcode 8:
import UIKit
import PlaygroundSupport
let v = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 600, height: 600)))
v.backgroundColor = UIColor.green
PlaygroundPage.current.liveView = v
Create a playground with that code and you should see a green box on the live view.
Remember to show the "live" assistant editor. See PlaygroundSupport reference for more.
This may be too basic or require rephrasing. I am in the process of learning Swift and iOS programming and have developed a basic application that runs successfully on my iPhone 5. The app consists of a label, a button, and a UIImageView. It looks the way I want it to on my iPhone 5.
I figured most of this out by just playing around and so I am creating all these elements programatically. The code looks like this:
let banner = UILabel(frame: CGRect(x: 10, y: 10, width: 300.0, height: 75.0))
let button = UIButton(frame: CGRect(x: 45, y: 75, width: 235.0, height: 60.0))
let imageView = UIImageView(frame: CGRect(x: 22, y: 150, width: 280.0, height: 410.0))
And then I configure them in viewDidLoad to make them show stuff.
Now the question...how to I make them all the right size when running on different devices? I can load up the app on my iPad Mini but it's all scrunched over to the left of the view. So I need to do some kind of dynamic layout but not sure where to start.
All help appreciated!
Rather than creating the view sizes explicitly with initWithFrame: constructors, you can programmatically create and NSLayoutConstraints to your views to automatically layout your views, the same as if you used Auto Layout with the Interface Builder. See Apple's Auto Layout Guide for more details.