On iPhone, How to display Animation while loading from server? - ios

I want to implement animation like This link while application interact with server.
If someone has example to implement this kind of animation then please provide me link.

Start animation
Server request in background thread
End animation in completion block of server request in the main thread
If you want that specific one I think you are going to have to make it yourself, but if you don't here are some open source alternatives.
DGActivityIndicatorView
MONActivityIndicatorView
YRActivityIndicator

interaction designer at Creativedash here =]
For something like that you'd make a png sequence, and set the animationImages property of a UIImageView. iOS is great at animating png sequences.
When your load starts, do yourLoadingImage.startAnimating() and when it's over (in the completion for your request), call yourLoadingImage.stopAnimating().
There's a property called animationDuration, and you need to set that as well, just to indicate how long the animation loop is - this doesn't indicate how long the animation will play for. It loops until you tell it to stop.
yourLoadingImage.animationDuration = 1 //set the loop duration to 1s
We actually did a short blog post on this process, and it can be the same for really any custom loader. http://news.ui8.net/create-a-custom-animated-loading-indicator-with-swift/

Related

Screen frame render finished / presented callback

I'd like to know the exact moment when screen frame finishes rendering and gets displayed, so I can capture specific window images with quartz api. There is CVDisplayLink / CADisplayLink that allows application to synchronise its drawing to the refresh rate of the display.
As I understand, those methods are very similar to what I need, but invoked when screen frame needs to be rendered, not when it finished and presented, meaning that if I capture the current screen image at that time I'd only see the previous render. Is this correct thinking?
If yes, is there a way to do get notified when the frame has actually finished rendered and was presented? Maybe there's private api for that? Ideally I need an answer for macOS, but if you happen to know how to do this in iOS, please let know.
P.S. I'm aware of CGDisplayStream, it's a great solution for capturing the whole screen, not specific windows – it uses run loops and dispatch queues, meaning that callbacks are not invoked in realtime like with display links.

Constantly refreshing background image of UIImageView IOS

How would I constantly refresh a background image of my UIImageView, while also still listening for touches and input? What I am looking for is the iOS Objective C equivalent (in java) of creating a new thread apart from the main thread, and having that thread be devoted to updating the background picture as fast as possible. Thanks!
It depends on where the new images are coming from. If they are a cycle of known existing images in your app bundle, just make this an animated image view (or an animated image) and the cycle will happen automatically.
If you need to run code e.g. to get out to the network periodically, then just start a repeating NSTimer. It calls you on the main thread, but your main thread code will be very brief indeed, and networking takes place asynchronously (unless you mess that up deliberately). Just make sure that when you actually set the image, you step out to the main thread, as you must never touch the interface in any way except on the main thread.

UISlider / touch events changes in iOS 7

I've encountered a problem with iOS 7 which I believe is related to the way events are handled.
I have a slider which upon changing it's value does some image processing which takes about 100ms to complete. In iOS 6, I could see the image change as the slider is dragged. After upgrading to iOS 7 it seems that the view is not redrawn between invocations of the value changed events. While dragging the slider, I can see the image processing start and finish numerous times but the entire view doesn't refresh (including the slider's thumb) until I stop sliding. Also the same happen when I add a gesture handler to the view which does the same thing. Has anyone encountered a similar problem?
Thanks.
Make sure you are not doing that processing on the main thread. I recommend using GCD to dispatch the processing onto a separate queue - it takes very little code and uses a well established pattern that is easy to understand.

iOS - QLPreviewController delay

I have an app that generates a PDF and displays it at the same time. As expected, there is about a 2-second delay between pressing the "Generate PDF" button and the QLPreviewController presenting the document. Not only that, it appears as though the document fades in momentarily, freezes, and then completes the fade-in.
I understand that the reason for the delay is because it is generating the PDF first, but the design of the application doesn't allow for any other mechanism. I was hoping to put a brief "LOADING..." animation before the QLPreviewController view appears, but everything I've tried so far still presents a 2-second delay.
Can anyone provide guidance on what I might be able to do here?
There are lots of options. I'd suggest that whatever you do, it be asynchronous. This will allow for the UI to not 'freeze' and you can put a loading screen up even if it is for 2 seconds.
There are many ways to implement this. Some involve actual background threads and others don't.
You can use, delegates, NSNotifications, blocks, NSOperations, and/or Grand Central Dispatch.
Here's a tutorial on how to use Grand Central Dispatch
Here's a tutorial on blocks

Trouble toggling the userInteractionEnabled property in iOS

I am developing a tic tac toe game for iOS and I am using a combination of UIButtons and UIImageViews to allow for user interaction and to display the moves made. My problem is that the buttons continue to accept user input before the cpu makes it's move, which breaks my game logic. I have made several attempts to toggle the userInteractionEnabled property, but I have only been able to turn it off. The engine that gets everything started in the game is my buttonPressed method. I also toggle the userInteractionEnabled property within this method and therein lies my problem: How do I re-enable the property after disabling user interaction? Is there a method that is called in between events that I can overwrite?
I have searched the web and I have searched through the developer documentation provided by Apple and I found information on the touchesBegan and touchesEnded methods. However, from what I understand, those methods need to be explicitly called which brings me back to my original problem of not being able to call those functions without the user's interaction.
If anyone can help, I would greatly appreciate it! I have been racking my brain over this for the past couple of weeks and I am just not seeing a solution.
I'd think that for a game like tic-tac-toe, calculating the countermove should be so fast that it can be done immediately in response to the first button press. If you're doing something complicated to calculate the next move, like kicking off a thread, you might want to reconsider that.
Let's say, though, that your game is something like chess or go, where coming up with a countermove might take a bit longer. Your view controller should have a method to make a move for the current player, let's call it -makeMove:. Your -buttonPressed action should call that method to make a move for the user. In response, -makeMove: should update the state of the game, switch the current player to the next player. If the new current player is the computer, it should then disable the controls and start the process of calculating the next move. Let's imagine that's done by invoking some NSOperation, so that coming up with the next move is an asynchronous task. Once the operation has come up with a move, it should again invoke -makeMove: (by calling -performSelectorOnMainThread:), which will again update the game state and the current player. This time, though, it should see that the new current player is not the computer, and so it should re-enable the controls.

Resources