Snapshot of complete UIScrollView - ios

i'm trying to create a snapshot of a complete uiscrollview, all the content size, i have searched a lot, and i have found something here on SO, like this:
Getting a screenshot of a UIScrollView, including offscreen parts
i have tried it, but there is a problem, because in the screenshot some element for example some UIImageView are enlarged or stretch, or in a different position, i can't understand why, anyone can help me to create this snapshot?

I'm not sure, but I think that UIScrollView elements are created and updated when they appear to the user. If so, probably their frames are not ready to be displayed when not on the shown "window".
Try to rasterize the content of your UIScrollView.
yourLayer.shouldRasterize = YES;
This way eveything should be updated at one time.

Related

Nesting scroll views

"It just works", or does it?
So I was going nuts trying to fit one ScrollView into another.
I get to the point when I actually made two separate xib files, did a scrollable label in one, and a scrollable image in another. Both are works perfectly in separate xib's.
After that I manage to open xib files as simple text(looks like they are formatted as XML or something similar) and simply cut scrollable image view(with all of superviews that I needed) into my main.(containing scrollable label)
So the idea was simple yet beautiful, I was like 90 percent sure it is going to work, because I inserted all the necessary view-scrollView-contentView stuff. And it is not. As you can see guys, image is big enough, views setted to be large and you can barely see tiny bit of it. So it SHOULD be scrollable, right?
Label with text keeps scrolling just fine, but the image wont move.
I was also trying to get scroll enabled via code, setting property to YES, but it wont help.
I also tried disabling auto-layout, thinking that it could be easier, but it was not much luck on the first attempt. Will be great to hear you guys thoughts, maybe I should disable auto-layout and try it out the old-way? Or is there a way to solve this puzzle as is?
Maybe my question was a bit long and not much of a readable, sorry for that guys, anyway I found my answer and will post a solution for any of you guys wondering about the same thing.
Just a reminder, I was trying to achive scrollable text+ scrollable image. Text should be scrolled up/down and the image should be scrolled in all directions.
So I find my previous attempt almost completely broken and started fresh(couple of times) and in the end I find the configuration that suits my needs.
Matter of fact, this particular configuration works almost exactly out of the box, most of the trick is get the right views in position. After that you just have to add missing constraints from the "Editor"->"Resolve layout issues" menu and get rid of few nonsense constraints that IB add god know why.(like those ones that adds 200pt blank space at the bottom or so)
After that you'll be pretty much set. If not, refer to the picture link, or github repo. Hope that will help someone.

UIScrollView zooming only to the size of UIImageView

I have UIScrollView in which UIImageView is held like on the screenshot:
My problem appears when I zoom and instead of being able to scroll only in the area of my image (subview of scroll view) I'm able to scroll around the original size so I get a lot of white space around my image which isn't what I want. You can see what happens on the screenshot below:
I wonder what should I update to keep my scrolling area only the size of the image?
After some research, some trials and errors I've finally achieved what I was planning to do.
First of all, I wanted to use only autolayout with IB which sure can be done but with some effort. After some digging I've found this technical note which by "Pure Auto Layout Approach" understands adding contraints in code but I was aiming at only IB which led me to this simple but beautiful solution called ios-imagescroll. After investigating this code with joy that I've finally found solution I came with some error but only on iOS 8 devices... iOS 7 worked like charm out of the box.
I assume that due to big changes in iOS 8 autolayout is more strict and you must be 100% sure what you want to accomplish. It turned out that this slight change MATTERS on iOS 8:
Of course, this bug, fix (call it whatever you like) was fixed by experimenting with everything but I guess that UIScrollView's content view (in that case UIImageView) must be the first item in constraint.
[yourScrollView setContentSize:CGSizeMake(yourScrollView.size.width, yourImage.frame.origin.y + yourImage.frame.size.height+35 )]; //let's say just 35 ...
yourImage may have x,y origins like (0,0) [I see a lot of space above it, so I assume you have set other values for x,y]

How to clip image to UIView animating over it?

I've been looking around here and seeing lots of questions that seem related, but I haven't found anything that's exactly what I need.
I have three UIViews that are animating inside a custom viewController. I want there to be a static background inside the viewController that is only revealed within the clipping bounds of the UIViews.
It's kind of like spotlights on a prison yard: the background should stay in one place, but as the spotlights move you can see different parts of it. Except that I don't need circles, regular old UIView frames are fine.
For instance, it seems like what I need is in the answer to this question: How to achieve dynamic UIView masking?
...the answerer provides a link to a page that shows how to statically mask an image, and then the answerer says "But personally I think i would make 2 UIImage views and crop the content of the draggable UIView"--without any info on how to do that.
How do you do that?

How Do I Create A Simple Scroll View That Scrolls Through Static Images?

Perhaps it's something with Xcode 4.5+ or iOS 6 that makes my research fruitless so far, but...
Apple's own advice hasn't worked for me. I set the contentSize to something different, and it causes no changes.
I found this wasn't unique to me, but the answer in that question 1.) does not inform me about the problem and 2.) I'm left wondering if it's really impossible to create a simple, non-inheriting example of UIScrollView. Thus, this question.
A better answer's code was tried within viewDidLoad and viewDidAppear, but to no avail.
So what gives? Is it possible to create a simple, image-filled view that allows scrolling? Say... something as easy as this basic project I set up on github -- but working?
Create and initialize a UIScrollView
Add it as subview to the view of viewcontroller
Make an array of image names
In a loop create UIImageView and add the images and add imageviews into scrollview considering the width of images, set the frame of imageviews
Number of images is known and the width it consumes can be calulated from the loop itself use it to set the contentSize of the scrollview

UIScrollView with multiple UIImageView shown

I'm trying to achieve scroll view with multiple images. I put the UIScrollView and put 3 UIImageView which the last one is out of bounds. I though that i can scroll the content of the srollview component. How could i achieve this. I have just found examples where the scrollView show just one picture at the time. How could i have multiple pictures shown in UIScrollView.
Something like this:
Thanks
OK the correct method which i was looking for is setContentSize. I thought that there is some setting to do this automatically to the included content. But as Grett writhed there is nothing like that. So i guest this is the only way do that.

Resources