Creating a smooth Gif Segue between view controllers like Vine Sign Up - ios

I have a sign up and sign in view controller and a moving gif background along with other storyboarded UI elements.
Currently I have the gif coding on each view controller obviously making the gif restart as I segue between each view controller and also more concerning having a quick pop of white before it loads whenever moving between the pages.
What can I add to my code to:
1. Prevent the white pop when it segues
2. Swapping between view controllers smoothly with the gif just continuing as if nothing has happened, so it looks like you move the UI not the page.
Look at Vine Sign In / Sign Up for reference as it basically functions in a similar way and want the background gif to function as it does on Vine.
override func viewDidLoad() {
super.viewDidLoad()
let filePath = NSBundle.mainBundle().pathForResource("beachwater", ofType: "gif")
let gif = NSData(contentsOfFile: filePath!)
let webViewBG = UIWebView(frame: self.view.frame)
webViewBG.loadData(gif!, MIMEType: "image/gif", textEncodingName: "UTF-8", baseURL: NSURL(string: "")!)
webViewBG.userInteractionEnabled = false;
webViewBG.layer.zPosition = -3.0;
self.view.addSubview(webViewBG)

As a starting point don't use a UIWebView for this. It is the reason you are seeing a white background just before the gif, the web view has been rendered on screen then shortly after the gif is rendered.
I'd recommend separating out the frames of the gif and loading them into a UIImage (and finally into a UIImageView) using one of the following techniques:
animatedImageNamed:duration:
animatedImageWithImages:duration:
If you don't want to separate the frames, use a gif rendering library such as FLAnimatedImage

Related

Programmatically scroll pdf in UIDocumentInteractionController

I'm showing a pdf file inside a UIDocumentInteractionController, like this:
let docController = UIDocumentInteractionController(url: documentsURL)
let url = NSURL(string:"itms-books:");
if UIApplication.shared.canOpenURL(url! as URL) {
docController.delegate = self
docController.presentPreview(animated: true)
}
I need to automatically scroll to the last page when the controller is shown, is there a way to do that? I didn't find one. Thanks to anyone who will send help!
I am afraid there is not a straight forward solution for this, even the documentation says it's a UIViewController but Xcode shows it is inherited from NSObject.
I'd recommend either rendering the PDF on a WKWebView or a UIScrollView. This will give you a room to wiggle.

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

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.
Why don't you use QLPreviewController or UIDocumentInteractionController?
Now in your case you can do it by using webView:
let req = NSURLRequest(url: pdf) //pdf is your pdf path
let webView = UIWebView(frame: CGRect(x:0,y:0,width:self.view.frame.size.width,height: self.view.frame.size.height-40)) //Adjust view area here
webView.loadRequest(req as URLRequest)
self.view.addSubview(webView)
Some tutorials:
QLPreviewController example
UIDocumentInteractionController example

How to show a webview (with all interaction) in secondary display, like apple Tv

I have a viewcontroller which has a webview attached to it. I wan't to mirror it to external screen connected to ipad. I am able to create new window and show images and all, but here i want the exact mirroring of UIWebview (all taps, links, textfield input in web page, video) on secondary display.
func initiateTheExternalDisplay() {
guard UIScreen.screens.count > 1 else {
return
}
let externalScreen = UIScreen.screens[1]
let externalWindow = UIWindow(frame: externalScreen.bounds)
self.externalSecondaryWindow = externalWindow
let roortVc = ExternalPresentationViewController() // this contains view to be shown
self.externalPresentationViewController = rootVc
externalWindow.rootViewController = rootVc
externalWindow.screen = externalScreen
externalWindow.isHidden = false
externalWindow.makeKeyAndVisible()
}
This is how i am instantiating the secondary display and is working fine. Suppose same class is showing the webview, can anyone suggest what info should i pass from here (or alternate way) to achieve mirroring.
I couldn't find any way to do so, so I used a work around. I taking screenshots of the web view controller and updating the secondary view at around 20fps, so it lags a bit but at least able to see the same interaction in almost rela time.

Scale UIWebView content

I would like to ask you about a problem that I'm facing with a project. The problem is that i'm trying to show a UIWebView control, I'm loading a video streaming into the web view , this is the code:
if(self.cameraUrl != nil) {
let url = NSURL (string: self.cameraUrl!)
let requestObj = NSURLRequest(URL: url!)
self.view_webvideo.loadRequest(requestObj)
self.view_webvideo.contentMode = UIViewContentMode.Center;
let zoom = self.view_webvideo.bounds.size.width / self.view_webvideo.scrollView.contentSize.width
self.view_webvideo.scrollView.setZoomScale(zoom, animated: true)
}
As you could see in the code I had research about that and try a lot of things but i can't scale the content, the video have width=360 and height=640, I can't change the video size because it is a third party service.
Also i'm using the property: Scales Page To Fit = true
I want the video scale to fix into the webview component and don't show any scroll
I hope somebody could help me with that.
Thank you in advanced
Try replacing the last three lines with this (similar to what manman said)
self.view_webvideo.stringByEvaluatingJavaScriptFromString("document.getElementsByTagName('video')[0].style.width='100%'")

UIscrollView image from web in swift

I want to make a gallery with UIScrollview like this.
In case, I want to get the images from web, but with this code my VC is very slow to load
var pageImage: [UIImage] = []
for d in image {
var imgUrl: NSURL = NSURL(string: "https://images.com/\(d.thumbnail)")!
var imgData = NSData(contentsOfURL: imgUrl)
pageImage.append(UIImage(data: imgData!)!)
}
How to make my VC load faster?
Only load the images when you actually need them. Use the scroll view delegate to find out when an image is about to appear on screen.
You should also not fetch the images on the UIThread which will make the app feel unresponsive. I would recommend using a 3rd party lib for loading and displaying the images such as SDWebImage or AFNetworking+UIImageView
as eric said you are loading imae on main thread you can set image in swift with url like imageView.setImageWithURL
or you can load image with background thread

Resources