Background gif position transition to other ViewController - ios

So the problem is: i have a gif background that was set through a method of extension created by this guy SwiftGif Link
I use method backgroundAnimated.loadGif(name: "giphy") to load current gif and it parses gif onto images then fills it onto arrays with consequent call of animatedImage method of UIImage class.
But the thing is - i want to preserve a state of looping gif when transiting to next ViewController through segue.
For example if i have bird flying over the centre of the screen and then randomly someone presses a button to go to next ViewController, gif resets and begins from the beginning. Help me to find a solution please
I thought of solutions:
Pass coordinates of frame onto other ViewController through prepareForSegue
Problem is - myBackground.frame is always at zero coordinates , so i have no idea how to get the frame it was stopped on last
Start with CGRect initial frame position
Problem is - its not possible to guess position of frame it has stopped when transition button is pressed.
Make one gif background for all ViewControllers (Have no idea how to implement such thing whatsoever)

Do you sure that your myBackground UIImageView is changing frame. I don't think so.
I guess its your gif is changing its key frame. So you need to store the index of the stopped key frame and start your gif from the key frame instead.

Related

UIView subviews updating visually but interact as though in previous state

I'm creating a UIViewController that houses some of RosyWriter's functionality, which I'm reworking to create a video recorder. The screen contains a title, a clipped-to-bounds subview that contains the AVCaptureVideoPreviewLayer (so the sublayer CALayer of the video content is added into that subview, so I think it's quite deep-nested), and two buttons acting like a toggle button - in the form of Start and Stop buttons placed in the Storyboard for the UIViewController.
The Start button works fine, even though the video's preview layer is on screen and showing the camera. When I start recording, though, I switch the buttons round, making the Start button hidden and the Stop button hidden=false.
The start button works - this is pressed when the video preview is on-screen and updating, but the actual recording (grabbing samples in buffers and writing them to a file - nothing UIKit related as far as I can see) has not started.
When the video recording is active, with the Stop button showing and the Start button hidden, the visible stop button isn't pressable, but the hidden start button can still be pressed.
I've tried moving the Stop button above the UIView containing the video, in case the CALayer or something else stretches outwith the clipped UIView bounds. This doesn't help. The stop button always acts as though it's not enabled - but it is enabled, and nothing appears to overlap the button. The button works fine if the UIView containing the video (which, I'll reiterate, is lower than the broken button) is never shown.
Can anyone think why this'd happen? I immediately thought about setNeedsLayout and setNeedsDisplay and tried just throwing some of those in, because it's almost as though the view had updated with my request to hide or show buttons, but an interaction layer hadn't updated.
Thanks
I now think this is due to my ignorant use (or misuse) of dispatch queues. I'm still not sure how I was able to interact with buttons that aren't showing - perhaps it's because their own state change responds in part, immediately, and the rest can't take place except on the main queue (the visual refresh, for example).
So I solved the problem, in a sense, by forcing a particular asynchronous delegate method to be called on the main queue. This doesn't affect the operation of this particular step in my recording process.

iOS UIView derived view instance drawRect being called but not updating on screen?

Was hoping someone could help with this please? I've scanned through the forum and apple docs and can't find anything that matches my problem exactly.
I'm trying to animate a custom 'Composite' UIView derived class (with overidden drawRect) by changing a custom colour property (not one of the standard view properties like centre, alpha, backgroundColour etc), calling setNeedsDisplay and redrawing the view using drawRect over X seconds duration to produce a slow colour change from say, red to blue.
At the moment, all Composite::drawRect does internally is clear the context (the view has a default background colour set to clear) and fill the view using the colour provided. This works fine the first time it's called - the view appears on screen in the correct red colour.
My problem is that when I try to animate the view by updating the colour property, even though drawRect is being called everytime I call setNeedsDisplay and the colour being fed into the view instance is correct the view doesn't update on screen until I stop calling setNeedsDisplay (or rather, stop updating the custom view colour property). It's like every call to setNeedsDisplay pushes the view to the back of a list so it doesn't get updated on screen until it stops getting called (even though drawRect is being called).
For example - trying to change the colour from red to blue over 10 seconds, the view stays red for 10 seconds, then turns to blue in a single frame at the end of the property changing (and presumably when I stop calling setNeedsDisplay) rather than a slow fade between the two over the time duration.
Any ideas what's going on? I'm guessing I need to animate this using apple's own animation property stuff but I'd really prefer not to - I'm trying to make this cross platform if possible and I don't see why my own method shouldn't work.
The basics:
In case it matters, my composite view instance is a subview of an UIImageView. (I know imageview drawRect doesn't get called but I can't imagine this is a problem for it's subviews - after all, my Composite::drawRect is definitely being called).
I'm setting the right colour on my view instance - I've debug printed this to be sure - so the colour provided to the view goes from red to blue over however many seconds / frames.
I'm setting setNeedsDispay and drawRect is being called every time - again, debug printing confirms this.
This is happening over multiple frames and the app goes through the drawing update at the end of every frame - I.e I'm not blocking the render thread or anything - the app runs fine, it just doesn't update the view on screen even though its drawRect is being called, until I stop manipulating the property. Someone mentioned a similar problem where they were blocking the render thread in a single frame but I'm definitely not doing anything like that.
I've tried messing around with the following but they all produced the same results (i.e. view changed from red to blue in a single frame rather than a slow change over).
Updating the colour every frame but only calling setNeedsDisplay on my view every Xth frame (5, 10, 20, 30 etc)
Updating the colour every frame but not calling setNeedsDisplay unless the corresponding drawRect call from the last setNeedsDisplay has happened (i.e. set a flag to false in SetColour func, set same flag to true in drawRect, test against it when decided to call setNeedsDisplay) - same results.
setting the view bounds with ContentMode set to redraw to force an update - same results
tried calling setNeedsDisplay on the parent image view too - no change.
I'm guessing that this just isn't possible - can anyone explain why its not updating the v view onscreen even though drawRect is being called? Any ideas how I should do this? I don't think I would be able to do what I want to do if I tried animated one of the default view properties using apple's internal animation system but if I've got to use that....
Thanks!
:-)

Setting the previous image right before calling transitionWithView

I have a placeholder UIImageView (loaded from a .xib) which I want to load with a picture of the back of a card and then flip to the front image.
[cardView setImage:backCardImage];
[UIView transitionWithView:cardView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[cardView setImage:frontCardImage];
}
completion:NULL];
The problem is that the initial image it starts with is not backCardImage, instead, it uses the no image (i.e. blank image) from my .xib file. If I had the backCardImage loaded in the .xib and only call transitionWithView, I believe it would work properly, but I would really like to have the two calls (setImage, and transitionWithView) in the same method. Is there any way to do this? Do I need to call something between the two?
I tried using UIViewAnimationOptionBeginFromCurrentState, but that doesn't work either.
The cardView won't draw, even if you put in setNeedsDisplay, until the next drawing cycle, so you need to set that image in another method first, or move the animation to another method, and call it with performSelector:withObject:afterDelay:. Even a delay of 0 will work. I don't think the animation looks very good though, because you only see the back image for an instant before the flip (a delay of .1 or .2 seconds looks better I think). Why not set the back image earlier? What's the purpose of a placeholder image in this context?

Open view controller with custom animation

I have an srollview with many images. After some image had touched I should open new view controller with this image and related images for image that was touched.
Now I use pushViewController.
So question is. Is it possible to open new viewController wiht zoom animation?
i.e. after user touched image, this image is zooming into the center of the screen (and this is new viewController already)
If it's possible please let me know with what I can realise it.
Thanks
I have good news and bad news for you. The good news is yes, it can be done! The bad news is that it can be complex.
The way I ended up doing it was as follows
when the user taps the image, you know what image to zoom, and you grab a reference and a frame
overlay a new view over the current view containing the scrollView, then add a NEW UIImageView containing another UIImage of the one the user tapped (could even be a higher resolution version)
animate that view to fill the screen (this image can be in a zoomable scrollview too, that's for future work!)
when you want to dismiss, you animate the frame down to be exactly whats in the scrollView, then you remove the overlay view
now users is more or less back to where they were before the tap

send thumbnail image to another view for bigger image view

i have 3 images in my display where i use CoreData to store them images and to view them in the display. Now i would like to touch these images and it goes large in another view. Ive tried using touch events bt nothing seems to work. Can anyone assist me please
You can put a transparent UIButton over the image and declare a IBAction on the button and get the image according to button tag. Then pass the image to next controller.

Resources