ios swift - scroll view over image doesn't scroll - ios

I want to have a background image that does not move and have a scrollview over it that allows users to scroll through content while the back image remaining static.
I have tried adding an image to my view and then after a scroll view over it but I'm unable to scroll.
I'm trying to achieve an effect similar to this:
Am I on the right path to achieving this?

You have to set contentSize for UIScrollView. ContentSize has to greater than frame size.

Related

Animate objects when UIScrollView scrolls

I have a UIScrollView which has two pages and only scroll horizontally.
The scrolling and paging is controlled using a UIPageControl. I have placed a UIImageView on the scrollView which contains an image of an iPhone (shown in red in the image below) that says Hello inside page 1.
I wanted to animate the UIImageView to rotate and change its position as shown in the image when the user scrolls from page-1 to page-2. Also the animation should ideally rotate back when the user is scrolling back from page-2 to page-1.
The animation or movement of the UIImageView is based on how much the user is scrolling horizontally and not based on time.
How can I rotate the UIImageView back and forth based on the scroll position of the UIScrollView?
Set a delegate for your scroll view. Probably you want your view controller to be the delegate. You need to add UIScrollViewDelegate to its list of protocols.
Then, in the delegate, implement scrollViewDidScroll:. In scrollViewDidScroll:, look at the scroll view's contentOffset. Based on the contentOffset, set the image view's transform and center to rotate and move it where you want.
To find by how much the scroll view has scrolled, you can check UIScrollView's contentOffset property:
contentOffset - The point at which the origin of the content view is
offset from the origin of the scroll view.
Then to rotate that image view, you could do this:
self.imageview.transform = CGAffineTransformMakeRotation(M_PI/2);
As far as the animation goes, I personally don't have much experience with it. But you could have a look at Simple Animation Using UIImageView.

ScrollView inside View or Vice Versa?

I am working in iOS and cannot find if there is a definitive answer to this.
I have a screen, the entire thing will scroll (not just part of it is scrolling at the top). I am using Storyboards to build this and the content is bigger than the screen size. Is the best way to do this with:
This is all inside of a UIViewController.
The content inside a View (child) inside a fullscreen ScrollView (parent) and set content size of ScrollView as the View's frame.
The content inside a ScrollView (child) inside a fullscreen View (parent) and set content size of ScrollView as its frame and then its new frame as the View's frame.
Just a ScrollView as the first child of the ViewController and set its content size as its frame and then its frame as the screen size (which I would need to check at runtime?)
All of these methods seem to work, but they make other things easier/harder (moving content for keyboard, etc.). Is it simply a matter of opinion or is there a "best/correct" method?
You have to set content size bigger than your view. Then It will scroll.

UIScrollview, other controls, not scrolling

I have an app which shows two images housed within a UIScrollview.
The scrollview is of size (320, 530), underneath it is an imageview size (320,38), this acts like a dock at the bottom of this screen, ( in fact it has to be there at the bottom of all screens in this app).
As it stand the scrollview works fine and the images switch from one to anothr when the user
moves the scrollview.
The problem is, I need the scrollview height to go all the way down ( from 530 to 568), and end up behind the dock imageview, when I change its height and the height of images within it, it just stops scrolling.
Is this impossible in scrollviews? does it have to have all of its screen real estate as top view?
Any solutions for this?
Thanks.
Update :
so I worked on the alpha and the image constraints, and the bottom imnage is located properly,
still the scrolling is not functioning.this is the latest code with changes.
http://ge.tt/4LYJGWl/v/0?c
thanks.
This is certainly possible. Add a full height scroll view to the controller's view, then add the small image view to the bottom. In the scene list at the left move that image view up so it's directly underneath the main view, which will make it a subview of that view rather than the scroll view (you'll then need to move the scroll view up above the image view so the image view will appear on top). You'll probably have to change some constraints to pin it to the bottom, and give it an alpha value less than 1 so the scroll view will show through.
After Edit
This is the screen shot of the scene from your updated code:
You only have one view that's directly under the main view, your scroll view. Compare that to my image.

How to implement this view for iPhone

The view I expected is like this image
The main view contains three parts: one label, one webview and one tableview. But the difficulty is their size are not fixed. I hope the webView can auto strech height according its content; the tableView's is similar to webView and its height should be decided by its content.
If webView's height is bigger than screen's height, I want to scroll the whole view not the webView.
I tried many ways but can't get the expected result.
You can achieve by using UITableView add your all component on UITableView cell by using cell.contentView and add table on your UIView.

How can I place a non-scrolling UIView underneath the scroll indicators on a UIScrollView?

I have an application where I'm using a zooming scrollView to do image cropping to a rectangle with a fixed aspect ratio. I have a mask where I darken the parts of the image that will be cropped. Currently I add this subview to the UIScrollView's parent, making them siblings, where this mask is 'higher' than the scrollview. Looks great. Except...
This mask is also masking the scrollIndicators and therefore looks a bit dumb. I could turn off the scrollIndicators, or, ideally, I'd like to place this UIView underneath the scrollIndicators, but not get scrolled with other content, which is what would happen if I made it a subview of the scrollview via [scrollView addSubview: myMaskView];
Anyone know if this is possible?
First, subclass UIScrollView so that you can modify the default behavior of scroll view.
Second create an image view with your image, and put both the image view and your mask view to a scroll view, this way your views will be underneath the scroll indicator.
Third, in your scroll view delegate method viewForZoomingInScrollView:, return your image view, so that only the image view zooms. Note that the scroll view will adjust the content size to be the size of the returned view, but it's fine as long as your image view takes up the whole content size.
And last, override layoutSubviews method, move the mask view to visible bounds of scroll view. The layoutSubviews method is said to be called every frame of scrolling, so the position change won't be visible to end user.
For more details you can refer WWDC session video "Advanced ScrollView Techniques".
EDIT: OK, just found that you can avoid overriding layoutSubviews by implementing the delegate method scrollViewDidScroll.

Resources