This question already has answers here:
UIScrollView not scrolling
(27 answers)
UIScrollView not scrolling…
(2 answers)
Closed 9 years ago.
Quite a simple bug. Unable to resolve.
I added a scrollview to my application. Next I added a view to this scrollview which is out of scrollview bounds. I was hoping the scrollview would allow my view to be scrolled.
but the view is not scrollable. i.e. I added a button to it, to see it is scrolling horizontally. However its not.
The kind of functionality I'm looking is like infinite scrolling with a long list of buttons, similar to http://www.cocoacontrols.com/controls/infinitescrollview
How can I achieve this?
You can set the property
[scrollview setContentSize:CGRectMake(x, y, width,height)];
width = 320*no of views you want to add in scrollview
height = You can put it height view e.g. 460;
and set frame
scrollview.frame=CGRectMake(x, y, self.view.frame.size.width, height) //self.view.frame.size.width=320 (iphone)
This is the simplest way to achieve above
and if you want it with the button click then use scrollview property
[scrollview setContentOffset:(CGPoint) animated:BOOL]
or
[scrollview setContentOffset:(CGPoint)]
hope it'll help
try
scr.contentSize = CGSizeMake(scr.frame.size.width, contentHeight);
Related
This question already has an answer here:
UIView layout being reset
(1 answer)
Closed 8 years ago.
I have a UITextView that takes up the entire screen. When the user taps on it and the keyboard is displayed, I want the UITextView to resize so that it only takes up the space not filled by the keyboard. Otherwise, some words will always be underneath the keyboard and thus uneditable. I'm changing the size with this line:
_textView.frame = CGRectMake(_textView.frame.origin.x, _textView.frame.origin.y, _textView.frame.size.width, _textView.frame.size.height - keyboardFrameBeginRect.size.height);
Where keyboardFrameBeginRect is the CGRect for the keyboard's frame. However, when the app is running and I double tap on the keyboard (to copy, cut, delete) it snaps back to its original size. How can I prevent this from happening or change the height so that this will not happen?
Resize the UIView containing the UITextView. Since your UITextView have auto layout, it will resize when the UIView size change.
Hi I have set in my storyboard a UIScrollView (of the same size of the view) and ctrl-dragged it in my code.
Now I have created a button programmatically using a simple algorithm of mine.
I then tried to
println(button.frame.origin.y)
which printed 1700.
Then I tried
println(button.frame.height)
which printed 142.2 (also coming from the algorithm). So the heigh I would like to reach while scrolling is 1700 + 142.2 = 1842.2
So i tried to hardcode the content size in this way
self.scrollView.contentSize = CGSize(width:self.view.bounds.size.width, height:2000)
But when I run the app I can scroll no more than the middle of the button, which is in numbers
1700 + 142.2/2 = 1771.1
Why the heck is that?
I did all this to try to understand how this UIScrollView works but I can't figure it out.
EDIT
Added a screenshot.
Inside the bubbles there is the button.frame.origin.y value. That's the max I can scroll leaving the screen untouched.
This is probably to do with scroll view insets - a mechanism where the edges of the content always appear under the navigation and toolbar.
You either need to manually account for this by reading the contentInset property of the scroll view, or using interface builder.
Scroll view Reference:
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html
This question already has an answer here:
Why button in storyboard is not located in appropriate location in ios8?
(1 answer)
Closed 8 years ago.
I have this UIView that located on top of the main view, I'm using AutoLayout and he is not responding. Than I read here that someone already had this issue and he fixed it by setting translatesAutoresizingMaskIntoConstraints to YES, so I did that, and now the UIView is located not where I wanted it to be.
At first the view frame was 0, 0, 320, 44 (thats on the top of the view)
Now its on the bottom of the view.
How can I fix that?
AutoLayout and UIButton Action don't have any relation.Please make sure your button is above the top view.It might be possible that your transparent top view overlapping the button.Make sure the user interaction of UIButton and its superview should be enable.
Can someone please guide me to a tutorial , on how to implement a vertical scrolling view on my iOS app?
I can't believe that the last 2 days , I can't find a single working example on just a vertical scrolling view. All the tutorials are about horizontal scrolling, zooming etc etc.
What I am looking for would be something like this tutorial http://www.edumobile.org/iphone/iphone-programming-tutorials/scrollview-example-in-iphone-2/, which shows how to make a uiscrollView and add objects to it, from the Builder and not programmatically. The only flaw I found was , that when trying to add a map down in the scrolling area, the map would appear up and not in the position I placed it. Maybe any ideas on that too?
Anything in mind?
So you want to create a scroll view in xib.
Add a scroll view to the nib file
set its size to to whatever you want
Add your controls (Buttons,labels..)
Add it as a sub view of main view
Finally create a property of scroll view and in viewDidLoad set the content size of the scroll view
self.scrollView.contentSize =CGSizeMake(320, 700);
It simple, same as horizontal scroll view.
Add a scrollview in a view hierarchy,
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];
Now to make scroll view scrollable, set its scrollview content size greater than its bound.
[scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width, scrollView.bounds.size.height*3)];
Now it can scroll three time the height of scrollView.
I've struggled with this simple issue for a full day. There are most likely benefits to a more sophisticated approach, but unchecking autolayout solved my issue.
For the quick fix, I believe this is the best approach and will save you a HUGE headache.
Just change the content size of your scrollview.Let's assume you are creating a UIScrollView with the following frame
scl=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 620, 172)];
Now call the content size property of your scroll view,like i have shown below .
[scl setContentSize:CGSizeMake(700, 172)];
Now add the scroll view on a view / View Controller etc and check it .
I am creating an application for the iPhone which involves having buttons which animate a image view, I created another view in which the buttons are held, however I would like to be able to horizontally or vertically, scroll this view of buttons. I have looked into adding scroll views and I have even followed a tutorial, But I just can't figure out how to add it to my app. Any Ideas anyone? In the tutorial I followed the guy adds the scroll view to the MainWindow.xib, now my app is created and designed in the viewcontroller.xib. So after following the tutorial when I hit build and go it loads that nib and all you see is a white background and a scroll view. (also in that tutorial he scrolled an image where as I would like to scroll a long view of buttons) I realize the newbie-ness of my question could be crazy, but I'm new to programming all together. Here's another additional question, if someone helped me get this scroll view working where would you design the contents of that scrolled view if it's length is longer than the iphone screen? Because It is my understanding that the space to design with in interface builder is the size of the iphone screen and designing interfaces longer than the iphone screen isn't do-able. (of course I know it is do-able I just don't know how to do it).
You can set the content view (scrolling area) dimensions programmatically:
[scrollView setContentSize:CGSizeMake(contentViewWidth, contentViewHeight)];
And then add you view components to the scroll view using the coordinate system of the content view. So say your scroll view was 100x100 pixels and you wanted the scroll view to be twice as wide:
[scrollView setContentSize:CGSizeMake(200.0f, 100.0f)];
You could then add a button to appear on each half of the scroll view:
// First half of content view
button1.frame.origin.x = 10.0f;
button1.frame.origin.y = 50.0f;
[scrollView addSubView:button1];
// First half of content view
button2.frame.origin.x = 110.0f; // NOTE that 110 is outside of
button2.frame.origin.y = 50.0f; // the scroll view frame
[scrollView addSubView:button2];
You could probably design each page of the scroll view as a separate sub view in the NIB and then shift the sub views origin to the correct page location either in Interface Builder or programmatically - but I have never tried this. If this works you'd then be able to layout your buttons using IB.
I would be interested to know if this works.
most views have a .hidden property.
set it to YES to hide -> myscrollview.hidden = YES;
set to NO to show -> myscrollview.hidden = NO;
you can put this hide/show inside an animation and fade out the scrollview.
look-up "simple quartz animation" - it only a few lines of code.