I have a two views of an ipad App which utilizes large UIScrollowView's, which appears to be leading to memory issues. I get my first memory warning when memory hits about 250MB. When using Apple Instruments, here are the largest of the All Heap:
VM: ImageIO_JPEG_Data, size 32.13MB
VM: CoreAnimation, size 32.13MB
VM: ImageIO_JPEG_Data, size 26.64MB
...
I have many images within the scrollview - which are all loaded into the storyboard, and I'm wondering if I reduce the size or resolution of the images it will fix the issue?
You could set up a system to delete/load certain images at certain points in the scrollview, so the app only has them in memory when the user is about to see them.
Because you said it's rather large, in the scrollview's scroll method, set variables to know what position the scrollview is in (eg: half way down, 10% scrolled, etc). If the user is sitting at the end of the scrollview (ie: unable to scroll down anymore (100%)) then they're not exactly looking at the images at the top of the view. You could then nil these images so that the app can re-use that memory. When the user is scrolling and the scrollview is near a certain percentage, you can then load those images that the user is about to see and nil the images that the user is far away from (this might cause a few seconds of 'whitespace' when the user is scrolling madly through your app, but that's okay because it won't take more than a few seconds for the images to all load).
Because these images are loaded into storyboard, I'm assuming you're loading them via UIImageView's. Simply give each one an outlet (hold control + click and drag it to your class's .h file and create an IBOutlet), then when you have the percentage of how far the user is down your scrollview you can know 'okay, the user is at 50% so I can get rid of the images from 0-20% and 80-100% of the scrollview',
you do this by:
//^Get scrollview scrolled percentage
//^find out where the user is, get a list of UIImageViews that are not visible on the screen
_yourUIImageView.image = nil //get rid of the image, clear memory up
//then when you need to add it again, assign an image to the UIImageview
Hope I helped.
Maximum do not load images in Storyboard,
rather you can do it through coding,like below
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *pathForImageFile1 = [resourcePath stringByAppendingPathComponent:#"filename.png"];
UIImage * image = [[UIImage alloc] initWithContentsOfFile:pathForImageFile1];
imageView.image = image;
image = nil;
Hope it helps!
Related
I am loading the images from server using SDWEBIMAGE library downloaded from github.
https://github.com/rs/SDWebImage
This is the view to my prototype cell.
Image width and height is set to static and View-> Mode -> Scale to Fill.
Now when i load images from server it does layout issues, image is not placed properly in image container and not even scale to fill, Overlapping every thing tried to find a solution but nothing work's:
Another Screenshot
Tried allot to solve the issue but nothing found, if possible the image should resize it self but not to change the layout constrain's.
Here is my code:
[cell.imageView sd_setImageWithURL:urlimage placeholderImage:[UIImage imageNamed:#"service-1.png"]];
[cell.imageView setContentMode:UIViewContentModeScaleToFill];
Thanks in advance.
Since you are loading the image async, constraints will be set before image is ready, therefore it will use the UIImageView's edges for constraints. But because of content mode UIViewContentModeScaleToFill, edges are not matching with image size at the run time until the download is complete. You can make loading sync but it's not a good practice since it will block the UI. You have to come up with different workaround.
You can post a notification when image loading is completed and set the constraints with received notification. Therefore view will use latest layout constraints.
Well pretty straight forward.
FBProfilePictureView uses (by my knowing) all the UIImageView methods. Knowing this i tried to use AscpectToFit (first in the storyboard second in the code when the first one didn't work.
the i tried this:
self.fb_background.contentMode = UIViewContentMode.ScaleToFill
This works only in height. I also tried resizing the frame this resulted in my images halfway down my page(instead of the top left
what am i doing wrong?
The problem is that my pictures width is not correct! its
The problem is that FBProfilePictureView contains a UIImageView and does not expose it for you to modify it's properties.
It downloads a square image if pictureCropping == FBProfilePictureCroppingSquare otherwise it downloads a small, medium or large image depending on the width of the frame. But there is no way to control how this image is scaled to fill the FBProfilePictureView.
I created a replacement view which exposes the UIImageView through a read-only imageView property and therefore allows you to control its contentMode.
Let's say I have a complex UIView, which is initially on the screen with quite small frame, let's say 80x80.
One of its subviews is an UIImageView displaying an image whose actual resolution is 1024x1024.
When the user tap the UIView i want the view to zoom in almost full screen so that the user can better see the image.
I know already how to scale a UIView to zoom in, my question is the following.
What's the best way to zoom in this view without pixellating the image?
I thought of these options:
I can actually set the frame of the UIView to the full screen size, and normally scale it down, so I'm sure that when it's zoomed in, it will be perfectly detailed. This solution anyway have a strong performance issue, cause moving around many of these scaled down views, will be quite an hit on the CPU/GPU.
I can do it just as I described, so small frame and scale > 1 to zoom in, but in this case will the image be displayed without pixellating?
I can actually set the frame to redisplay the view at the big/small size. In this case the detail will be good, but I have a performance hit here too, because my UIView have around 15 subviews that need complex calculation to relayout, so it's not so "fast" to set the frame.
Which is the best solution? Or do anybody have any other better solution?
Why dont you just have thumbnail representations that are 80x80, and when the user taps on any thumbnail, you transition from your current view containing all the thumbnails to a new view with the +transitionFromView:toView:duration:options:completion: method and simply display a UIImageView with the full resolution image loaded into that new view :)
I have a UIView in which I get certain information about a user, wthin a bunch of textfields and a bunch of photos of him, if available.
No Im a bit limited here, so I must have a UIImage or UIImageView on my View (only the first half of my view, to display this images.
Up to now I have a array of this images in the background and as soon as the user swipe over the UIImageView, the image shows the next.
But it's ugly, becuase there is no real paging (you know, see the second image in pieces while you swipe, at the moment its only a UIMageView.Image = xxx and its ugly) and no zooming (zoom on click).
Any idea to solve this?
Use an UIScrollView and place all of the images in it (as UIImageViews).
How to make the gallery looping.when last image in the gallery finished i want to show from the beginning.(horizontal auto scrolling the images from right to left).Please help!
Here the code below for scrolling but i want to scroll continuously when last image over
addEventListener(Event.ENTER_FRAME, leftSideScrolling);
private function leftSideScrolling(e) {
galleryWidth = rootClip.imageContainer.width;
speed = -(0.02 * (980 - 620));
rootClip.imageContainer.x+=-2;
if (rootClip.imageContainer.x>0)
{
rootClip.imageContainer.x= (-galleryWidth/2);
}
if (rootClip.imageContainer.x<(-galleryWidth/2))
{
rootClip.imageContainer.x=0;
}
}
Instead of scrolling the container, scroll the images inside the container.Assuming you're scrolling from right to left, when an image x is inferior to its width , meaning that the image is out of view , add it to the end of the image container, which would be the total width of the container minus the width of the image you're moving. that should do it!
Maybe you need to have progressive loading if you have many images in order to load certain amount at the time, but if you wish to go with what you have, then throw a loading flash movie when loading an image, limit loading amount of images, once user start to scroll, hide off screen images and load next x amount of images. As PatrickS mentioned, scroll images (flash movie clips) instead of container. All images should be located under a movie_clip to apply effects, all movie clips should be located under container to have scrollbars and move positions with AS1/2/3.