I am trying to create an animation using a UIImageView with an array if images. It works great, except that I need a different delay between some of the frames. In an animated gif you can set the delay between frames. Every example I see of an animated UIImageView has a fixed delay between images.
Does anyone know how I can set a different delay between frames? Or, is there an example of such?
Maybe UIImageView is not the right thing to use, so if anyone has an alternative please let me know.
I have posted a similiar question in other forums and no one seems to be able to answer this. It seems like it should bo doable, since .gif images have had this forever.
Thanks
It may seem hacky, but:
From UIImageView documentation:
animationImages
An array of UIImage objects to use for an animation.
#property(nonatomic, copy) NSArray *animationImages
Discussion
The array must contain UIImage objects. You may use the same
image object more than once in the array. Setting this property to
a value other than nil hides the image represented by the image
property. The value of this property is nil by default.
So you need to add your UIImage several times to the array for a delay.
UIImageView does not support a different delay between different images. You will have to use multiple UIImageViews and manage the transition between them manually if you want to have different delays between frames.
Another approach would be to use a UIWebView which is sized exactly to fit a .gif image that has the delay settings you want.
You have to use different UIImageView to get this working. Try this application page. Might be helpful for you. Link: http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial
If you would like to try my animation library in your iOS app, it offers a complete solution to this problem. For example, you could take a look at the APNG app, it is a free app in the iTunes store that displays animated APNG files. This app was created using my AVAnimator library which contains APNG and GIF decoding support. The APNG format works just like a GIF in the sense that each frame can have a delay time, you would use existing software to create the APNG in this case. But, it is easier to just encode a new .mvid file (this is a custom video file format) from a series of PNG imags. To create a longer delay, you simply repeat frames that do not change in the input PNG image series. Either approach could be used to create an input movie that could display with a variable amount of time in between specific frames (the overall FPS would be the same, but specific frames can simply repeat so that they do not change for say N frames in a row). You can also implement specific user interactions like starting an animation, pausing on a specific frame, and then starting again from that same frame.
Related
i have a collection view with lets say around 50 objects, each object has one of three images based on its category (never mind it), also each object (that becomes a cell) has two CATextLayer objects and a logo (each cell has a unique logo).
i have created a reusable cell that contains all of the above parameters - the category image is assigned to the cell contentView.layer, the logo is a calayer (which i create when the cell is first created and then just change it value - rather than adding a calayer each time cellforitematindexpath is called) and by the same technique change the catextlayer which differs from cell to cell (based on the datasource object info).
everything works well but the scrolling is very slow on an iPhone 4, i guess thats because that for every cell that gets called i go fetch the logo (which is on a directory). the category based images are instantiated as a layer when view load (so i don't need to fetch them when a cell is called) - thats faster but what can i do with the logos ? i cannot initialize 50 images and have them eat all of my memory.
i have a solution that can cause fast smooth scrolling - initialize the first objects that the user sees in the collection view, and load the cell parameters only when there is no dragging or decelerating - and than use uicollectionview.visiblecells to which cells i need to load.
but i don't want that - i want the user to scroll and see all of the cell parameters
instead of a activityIndicator.
do u have some other approach to this?
btw
i used to use UIKIt for all of that but i moved into Core Animation because i got the impression it will be faster.
tnx.
See WWDC 2012 videos iOS App Performance: Responsiveness and iOS App Performance: Graphics and Animations for some tutorials on how to use Instruments to identify the problem.
If you haven't done so already, I'd move to making the image retrieval process asynchronous. Also, if your images are large/i.e. being resized, you might want to save/use the resized/thumbnail rendition, which can improve performance. That former video even talks about the idea of replacing a complicated set of labels on a busy UICollectionView with image snapshots.
But, as David said, until you run it through time profiler, we're just guessing. To paraphrase the workflow Apple uses in those WWDC videos, you have to use instruments to quantify/identify the precise problem, form a hypothesis, quickly test that hypothesis before investing too much time in the solution, and if the hypothesis stands up to scrutiny, only then dive into implementing solutions.
There is one library to load images in the back ground. it follows the concept of lazy loading. if you use that your app scrolls smoothly.
In the following library there is "EGOImageView". use this class in place of ImageView and set the image paths to "ImageURL" property
EGOImageLoading
incase if you won't find EGOCache files in that, then download those from the following link
EGOCache
Regards,
Satya
I have an iphone app that gets jpeg images through wifi at a rate I can control and displayes them using a uiimageview. it seems that the best performance i can get is about 2fps. it lookes like the uiimageview cant handle [uiimageview setimage:image] quickly.
is there a better solution other than using uiimageview that will allow me a betterframe rate?
I understand you need JSon to pass multiple info from your service but clearly re creating your image from a json string consumes both memory and processor time. Use the Json to pass the url of the bytes instead and retrieve the bytes using another get.
I expect you to have a json like { path = "/images/funnryrabbits.jpg", anyProperty: "anyValue" }
Try using the .animationImages property of UIImageView. It takes an array of UIImages and animates them like a flipbook or an animated gif. You can make some cheap but quick animations by putting in a bunch of slides and letting UIImageView do the animation.
I don't know if you can manipulate that array as it's rendering the animation, is the thing.
I have a large png Image that I need to Zoom&Move.
I therefore created a UIScrollView and embedded a UIImageView.
The App works fine in the simulator, but when running it on the device (8GB iPod Touch) it crashes as soon as the view is loaded.
I tried with a smaller test Image (4MB) works fine and suspect the iPod can't handle a 20MB PNG. I also tried different other formats, such as JPG (in various save patterns), but that did't help either.
Any clues how I can solve this?
Ouch, 20M is a large image. The first thought that comes to mind is can you dice up the image? I.e. instead of one image have a whole bunch of small images which together make up the larger image. Then you can load on demand the same way google maps downloads image squares.
have a look at the ScrollViewSuite Example from apple. Sounds exactly like what you are trying to do.
3_Tiling demonstrates:
How to subclass UIScrollView to add content tiling
Reusing tiles to optimize performance and memory use
Changing the resolution of the content in response to zooming
I suggest the Example Photoscroller. It demonstrates CATiledLayer which you can use to tile your image and even use smaller images as lod images. It's much smaller then the complete ScrollViewSuite example but has everything you need to do what you want. It contains only 2 classes which you should be able to use in your project with minor edits.
You might want to check the WWDC 2010 Session #104 "Desinging Apps with Scroll Views"... they handle and explain that example.
You will need to tile your image. I suggest imagemagick for that :)
First: I've implement a fairly complex scrolling mechanism for images, that allows to scroll over a few hundred thousands (theoretically) in one single scroll view. This is done by preloading small portions upon scrolling, while re-using all UIImageViews. Currently all I do is to assign new created UIImage objects to those re-used UIImageViews.
It might be better if it's possible to also re-use those UIImage objects by passing new image data to them.
Now the problem is, that I am currently using the -imageNamed: method. The documentation says, that it caches the image.
Problems I see in this case with -imageNamed:
As the image gets scrolled out of the preloading range, it's not needed anymore. It would be bad if it tries to cache thousands of images while the user scrolls and scrolls and scrolls.
And if I would find a way to stuff new image data into the UIImage object for re-using it, then what happens with the old image that was cached?
So there is one method left, that seems interesting:
-initWithContentsOfFile:
This does not cache the image. And it doesn't use -autorelease, which is good in this case.
Do you think that in this case it would be better to use -initWithContentsOfFile:?
Only a benchmark can tell you for sure. I'm inclined to think that UIImage image caching is probably extremely efficient, given that it's used virtually everywhere in the OS. That said with the number of images you're displaying, your approach might help.
I'd say YES. You have too much images to keep all of them in cache so you can't use -imageNamed:. If your images are not displayed many times, you will not get lower performance.
I found one link regarding this which comments of imageNamed method http://www.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/
I'm currently using a UIImageView with an array of images to create a small looping animation sequence with about 20 images in there (at 320x480). Whilst this works okay for 20 - 30 images, any more and the app quits on the iphone. There is nothing else in my test app at the moment so I know it's just down to the animationImages sequence.
Has anyone come across any samples of doing this type of thing through Core Animation to achieve better performance and allow many more images? From what I've read it sounds like its possible to set up a ton of CALayers and put an image in each, and then create the animation by manipulating the layers on and off in sequence. Is this a good way to do it?
Or, alternatively, as I'm basically after the effect of a looping movie, is there a way to use the moviecontroller to achieve the effect without it fading in and out at the start and at the end?
I'd be grateful for any pointers. Many thanks.
This could be a simple memory issue. 20 images (320x480) is about 3 MB of memory, assuming 8bpp (if they're higher color, obviously even more). You might try loading and unloading as needed (though, of course, that'll mean rolling your own animation, rather than using UIImageView).
Sounds like a simple memory issue.
You could load one or two frames at a time, or actually play a movie instead.