I am currently programming an application for the iPhone and I am having some issues with my horizontal (horizontal as in you scroll horizontally, not vertically) UIScrollView.
The UIScrollView's height is 260 and the width is 320. It has 2 pages and each page has a UITableView in it. The UITableView's frame is the same as the UIScrollView's frame.
The problem is that 80% of the time, the current UITableView detects the drag/swipe as a vertical scroll (but it's actually horizontal) and begins to scroll the table view vertically.
My question is the following:
Can somebody explain to me how the app Reminders does for the scrollview scrolling. If you look carefully, you can see that the scrollview handles the horizontal scrolling very well and that a horizontal scroll is handled by the scrollview (and not by the tableview like mine does). If anyone needs more explanation please leave a comment.
If I try to scroll to the left/right in the table view of Reminders, it doesn't respond to it. If I scroll in the table header view where the add button is, it scrolls without any problems. My guess is that they made the table view header a UIScrollView. Apple highly discourages the use of a table view in a scroll view (or any view that inherits from UIScrollView into a different view that inherits from UIScrollView, for that matter), so they probably wouldn't take their own advice and ignore it.
Related
I have a child View Controller within a Container View that hosts a vertically-scrolling UITableView. Tapping a Button expands a separate View that covers the UITableView in the child View Controller. This new View contains a vertically-scrolling Scroll View. No matter what UITableView settings I change, I am unable to scroll the Scroll View unless I remove the UITableView entirely.
I am currently porting my fully-developed Android application to IOS, and my experience with Android Studio leads me to believe that this is an issue with the UITableView stealing focus from the Scroll View.
In short, how may I temporarily remove focus from the background UITableView to allow the overlaid Scroll View to scroll?
With Scroll Views up until this point, I have been setting the bottom -> Superview constraint to priority: 249 since I was having issues setting the contentSize. For some reason, having a Table View in the background disables this effect. My guess is that this happens because the Table View is forcing the Superview to anchor based on its own constraints, and therefore the Scroll View can no longer adjust based on low-priority constraints. Changing the Equal Height parameter of the Scroll View -> Superview to a proportional relation (x2) has temporarily addressed the problem.
I am pretty sure this has something to do with the dreaded AutoLayout. (been trying since 2days to get hang of it)
So I mastered it somewhat, but now I have problem where my UIScrollView is not scrolling fully down, pictures are much better at explaining these things
this is the scroll view
this is the content view
so the problem is the scrolling is happening but then again it springs back up. So I am not able to click on the signup button
EDIt 1
Edit:
I have created a little example on github for you to look at, here. The project illustrates the answer below and uses the techniques I describe and nothing else.
Original Answer:
couple of things I would advise here.
First, I know you've been trying for a while but remove all the current constraints (painful I know but). Do this for clarity as ....
The view should be the size of the scene, it looks like you want the scrollview to be the full screen so that too needs to be the size of the scene.
e.g. if you are designing at 6Plus by default the scene size is 414x736 so the view and the scrollview it contains should also be 414x736.
Only the content view needs to be the size of the real content you wish to show. Let's say for arguments sake that the content is 414x1000.
Now the constraints for the scrollview are simple. It needs zero spacing to all it's edges.
You can add the content view to the scrollview in a couple of ways. The way I try to do this varies from project to project and depends mostly on how complex the scene is. If it's a really busy scene I keep the content view outside of the scrollview in interface builder so that I can work on it easily and visualize the whole of the view. Then I add the content view to the scrollview in code.
If its a simpler view You can add it inside the scrollview in interface builder. Ultimately whichever way you do it, you can lose visibility of the content view in interface builder because the contentview is larger than the scrollview and the content gets obscured. So play about and find a good way for you.
Define the content view and all it's subviews. The content view needs to be taller than the scrollview otherwise it wont scroll. All of the content view's subviews need to have defined heights from top to bottom and widths from left to right. In your case the scrollview is scrolling vertically not horizontally so all the widths need to add up to the width of the scroll view BUT the heights need to add up to the full height of the content view.
Note: if you do this proportially your life will be easier later. If you do all this with fixed heights the storyboard will break on different device sizes.
Now the "tricky bit" and it's a bit counter intuitive. You need to pin the content view to the scrollview, remember the height of the content view is taller than the scrollview. In all other circumstances in Interface Builder pinning a view to a superview (0 padding) will adjust the height (or width) accordingly. For the relationship between a scrollview and it's content view this doesn't happen.
First pin the contentview
Notice the -400? Remember the content view is taller than the scrollview and we will change this immediately.
Select the bottom constraint (-400) that we have just created:
Select the drop down arrow next to the constant value:
Select Standard Value and type in 0 for the constant.
You should now have a storyboard with no broken constraints and if you build and run you should get a scrollview as desired.
Your bottomspace to superview on your content view is set to -74.0, I don't know if there is a reason you had to do that, but try setting it to -8.0. I think your scroll view is scrolling up to the 0.0 mark automatically
I have added some uitextview in my uiviewcontroller.But some of the textViews are not seen as view is small compared to the number of textViews. So I want scroll it, so that i can see the other textViews also. One more thing-- when i want to type something in the lower textView then it hides because of the iphone keyboard.If somebody knows about it, please give me with the solution.Thanks a lot.
Add UIScrollView in self.view. Now add all subviews to UIScrollView.
Provide contentSize of UIScrollView in width and height.
if heigth > 460 it will scroll vertically
if weight > 320 it will scroll horizontally
If any condition doesnot matches then u will not be able to scroll
You simply have to use UIScrollView.Instead of adding all of your subviews(in your case multiple UITextViews) in the main view, just add a srollView in your view and then add all subviews in that scrollView.UIView doesn't have the property to scroll.And don't forget to change the contentSize property of scrollView.
You must implement a UIScrollView. This is a fundamental class when it comes to iPhone development (and just Apple development in general) and it should be mastered before you continue onto more advanced topics. Here is the documentation for the class :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html
I have an interface which will have a text view and a table view below it. My current view looks like this
UIScrollView
UITextView
UITableView
Currently the TextView and TableView can scroll vertically..but what i want is the whole screen to scroll up/down. Why doesn't this work properly?
You can put a TableView inside a ScrollView, but you must resolve conflicts between touches, scrolling, and bouncing in IB or with code, and you must set the ScrollView's contentSize with code, not in IB.
If the TextView really "belongs" to the table, consider putting it in a table cell, or better, as a header, that's what they're for.
I wonder if UIScrollView has got an "hidden" subview acting as an container for the content. If I scroll a scroll view, is that content view moved up/down in the scroll view? Or is the scrolling offset applied to the bounds of that UIScrollView instance?
Or: Does UIScrollView use an additional view as container, or is all content added directly to the view? The documentation doesn't tell much about wether it has a content container or not.
UIScrollView doesn't have a content container but it is standard practice to create one yourself and add all your subviews to it. It's not necessary, though, at least as long as you use the scroll view just for scrolling. If you need the zooming functionality, too, having one content view often simplifies things because the delegate method viewForZoomingInScrollView: requires you to return a single view.