Creating UIScrollView in Storyboards - ios

I simply have a ViewController and added UIScrollView into that. Later on I created UIImageView which is larger than UIScrollView and inserted into the UIScrollView.
However when I run the simulator, UIScrollView does not scroll. I can bounce it but it does not simply leave it's current position within the UIImageView.
I also tried using [scrollView setContentSize:CGSizeMake(320, 640)]; within my viewDidLoad and it did not really work.
So how can I make the UIScrollView to actually scroll?
I am using Xcode 5 and iOS 6.1

Set the contentSize in viewDidAppear rather than viewDidLoad. Make sure scrolling enabled is checked in the storyboard under the attributes inspector (select the scroll view and press the shield icon on the right top).

Related

UIScrollView works perfect in new project but did not scroll in xib based project

I am facing a weird issue, scenario is I am working some other's code and there is viewController for profile and there are textfields in viewController.. Let me explain briefly the hierarchy of viewController
View
-UIScrollView
-TextFields (A lot of)
-UIButtons
Issue is when I drag finger on UITextfield the scrollView do not scroll and if I drag other then Textfields view or empty view and even on UItextView the scroll works.
More I have created a new project in Xcode 7.3 and copy scrollView from the actual project I am working to new Project and enabled the property DelaysContent in ScrollView and it's working perfectly even if I dragged on textfield view..
Can someone help me regarding this what should I do.?
I think If you create textField programmatically, you would not have added to ScrollView.So add to scrollView.
[viewTextField addSubview:textField];
[scrollView addSubview:viewTextField];
Then content size for scroll view is important
CGSize contentSize = scrollView.frame.size;
contentSize.height = 500; //Please set your required height
[scrollView setContentSize:contentSize];
Before that you have to set the delaysContentTouches and canCancelContentTouches to YES or NO depends on the below suggestion.
UIScrollView with Buttons
Adding Button to ScrollView

UITextField Not Responding UIScrollView Xcode 7.3

I Have a UIScrollView in my ViewController and ContentView in UIScrollView.
There are various other Views in the Content View to make understanding of the used labels and textfields more readable
Here is a screen shot to help you understand the hierarchy of the viewcontroller
All the Constraints are set properly I can see the views as they are aligned in storyboard on all size of devices, userInteraction is enabled on all the textFields and UIViews (I triple checked) still I'm not able to edit text on the textfields that are not immediately visible on the screen when the view controller is launched.
i.e. If the first three UItextFields are visible when the viewController is launched (4.0" device) they can be edited or if the first Five UItextFields are visible when the viewController is launched (5.7" device) they can be edited while the rest do not respond to user interaction
I've checked if they are in any case are overlapped or not by changing the background color of all the Labels, TextFields and Views. Nothing is overlapping anything, all are where they should be.
Content Size is set for scrollView in viewDidLayoutSubviews
-(void)viewDidLayoutSubviews {
[self.scrollView setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1724)]; }
The Height 1724 will never change no matter the size of the device on which the code is running
Please check your contentview size or setbackground color for scrollview and contentview. Contenview size is not increasing i think.

UIView at bottom UIScrollView does not appear

I'm trying to get an UIScrollView working with my Storyboard. It works but the UIView at the bottom that I use with a gesture tap for getting back is not showing. How can this be?
So everything works expect that. This are the things that I did:
Set freeform in Storyboard
Disable auto layout for the Storyboard nib
Changed the freeform dimensions to X:320 Y:800
Dragged some labels and stuff in the Scrollview
Created an outlet for the ScrollView
Enabled scroll programmatically
Enabled Contentsize CGMakeSize() programmatically;
So I normally did everything, why isn't my UIView showing up at Y:750. The only thing I do with the UIView is setting the Background/CornerRadius.
It would be if your UIView is no included in the calculation for the content size. Other than that I cannot see anything obvious.

UITableView creeps underneath button

I created a UITableView with a button underneath. When I run the app on iPad in portrait, the UITableView creeps under the button, like so:
I am clueless as to why this happens. It only happens on iPad in portrait, so I don't think it's a Xib problem.
I would very much appreciate any help with this problem.
You may need to set the UITableView's frame manually when the iPad in portrait as the UITableView may be autoresizing with traits such as sticking to the button of the screen like below. You can play around with the resize options of both the UITableView and UIButton to get this right.
To set the frame manually, set a CGRect to the frame of the element.
tableView.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height - uploadButton.frame.size.height);
In this example, uploadButton is the UIButton at the bottom and you are resizing tableView to fill the screen except to the uploadButton at the bottom.
It looks like your tableView's content is not clipping to the bounds of the frame. Try setting clipsToBounds to YES for the tableView.
You probably need to add an autolayout contraint to keep the bottom edge of the table view and the top edge of the button a certain distance apart.

Why UIScrollView does not scroll when I put a UI element inside it?

With Xcode 4.5.2 I created a Single View Application. Using Interface Builder I populated the view with an UIScrollView. In my view controller I added an outlet like so:
#interface ScrollerViewController : UIViewController {
IBOutlet UIScrollView *_scrollView;
}
I connected the outlet using Interface Builder to the actual scroll view.
The viewDidLoad of the view controller method is
- (void)viewDidLoad
{
[super viewDidLoad];
[_scrollView setContentSize:CGSizeMake(320, 700)];
}
Running the application now I can scroll the scroll view like I would expect. I can see that is working because the scroll bars appear when I swipe the view.
Now when I drop a label (or a button) inside the scroll view the scroll view stops working. It does not scroll anymore. The label does not move and the scroll bars do not appear. It works (scrolls) again when I remove the label.
Any Idea what I an missing?
EDIT:
You can find my toy project on GitHub.
I think that the scrolling only works if the content size is larger than the frame of the scroll view. So try making it larger if it isn`t.
Hope this helps!
EDIT:
Ok, found the problem. Turn off the auto layout from IB.

Resources