0

Created ios app using scroll view. The height set to 3000 but cannot scroll past 2000. Is there a height limit? The view controller set to 3000 in IDE.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • There is no arbitrary size limit, at least not a reachable one. Show us your current code. – Tamás Sengel Aug 03 '17 at 14:32
  • There is a memory limit. – Retterdesdialogs Aug 03 '17 at 14:33
  • @Retterdesdialogs In what way? – meaning-matters Aug 03 '17 at 14:48
  • @meaning-matters in generell. To use a scroll view with a height of 2000 is probably not a good idea in case of memory management, because the content gets rendered even it is not visible right? – Retterdesdialogs Aug 03 '17 at 14:57
  • hmmm??? I just ran a sample app with a scroll view, height of 128 and content size (using constraints) of 3000... added 30 labels at Y coords of 100, 200, 300, etc... No problem scrolling down 3000 pts to see the #30 label. – DonMag Aug 03 '17 at 15:22
  • @Retterdesdialogs iOS is not stupid, nothing gets rendered that's not visible. Then we're not talking about what on the view, but merely about plain size. Just try it, make a scrollview of 1x1 million, I'm sure it will be perfectly fine. – meaning-matters Aug 03 '17 at 15:25
  • @meaning-matters sorry, rendering was the wrong word. In memory. – Retterdesdialogs Aug 03 '17 at 15:32
  • @Retterdesdialogs Doesn't matter, there won't be any issue with massive scroll areas. – meaning-matters Aug 03 '17 at 15:42
  • 1
    @meaning-matters Ok, thank you for the correction. I will keep in mind – Retterdesdialogs Aug 03 '17 at 15:43
  • I am drawing a grid on the scroll view. The scrollview sits on top of the view controller. Does this change anything? – user3757894 Aug 03 '17 at 17:46
  • @user3757894 - you need to provide a little more information. Are you manually setting `.contentSize = ...`? Or are you using constraints? When you say you *"cannot scroll past 2000"* -- how are you determining that? Checking offsets? Looking at visual elements you've created? Saying "it doesn't work" is really vague... – DonMag Aug 03 '17 at 18:50
  • Ok. Here is what I did, I created universal one view program. I added Scroll view(SV). Set the view at 3000, set the scroll view at 3000 and told the system thru the IDE to make the SV the same width and height using the ruler and constraints. I put a label at top of screen and bottom. I should be able to see the top label and bottom label in simulator. I cannot scroll to the bottom to see the bottom label. Can someone create a simple ipad app and see if this works for them? – user3757894 Aug 03 '17 at 19:12
  • You are a bit confused about how a `UIScrollView` functions. You want to add a scroll view to your main view, then add *content* to the scroll view. Then, either via code or constraints, define the *content size* - that will be the size of the "scrolling area" within the scroll view. – DonMag Aug 03 '17 at 19:17
  • @user3757894 - there are lots and lots of tutorials and articles out there, but often throwing in higher-level concepts. This one looks like a decent "just the basics" tutorial: https://ios-tutor.blogspot.com/2014/11/this-is-my-second-post-in-ios-tutorial.html – DonMag Aug 03 '17 at 19:28
  • @DonMag I found some code you created that programmatically created a scrollview and added 2 labels with the bottom label set to 400 pts from the left and the constant to 1000. This worked when I ran it. However, when I set the constant to 4000 the bottom label disappeared when I scrolled. Same thing at 2000. When set the constant back to 1000 it reappeared. Can you run this program at 4000 constant to see if it is working for you? And if it is, there must be a configuration issue with my IDE. – user3757894 Sep 07 '17 at 15:11
  • @user3757894 - hmm? Which code are you using? – DonMag Sep 07 '17 at 15:15
  • Don, Here is the link:https://stackoverflow.com/questions/44931898/using-scrollview-programmatically-in-swift-3 – user3757894 Sep 07 '17 at 15:48
  • @user3757894 - take this to chat? https://chat.stackoverflow.com/rooms/153890/donmag-misc-chat – DonMag Sep 07 '17 at 15:55
  • Don, I can chat but I am not sure how to start it. The page looks a little confusing. It also says on the page that I must have 20 brownie 20 pts to chat. – user3757894 Sep 07 '17 at 16:17
  • @user3757894 - Ah - sorry... well, I just copied / pasted the *exact* code from that post into a new Playground page, saw I could scroll down to bottom-right label... changed the `labelTwo.topAnchor` constant to 4000, and... no problem. Gotta scroll-scroll-scroll, but eventually it gets to the label. I also pasted it into a new project and ran it on a device... again, works as expected. Just changed it to `14000` just for the heck of it, and again - long time scrolling, but it's there. – DonMag Sep 07 '17 at 16:31
  • Ok. There must be something wrong with my IDE. I am using this program as an Ipad program. I am using a 9.7 ipad Air in landscape mode. I create the program and put your program in the viewController.swift and run it. Is that what you do? Maybe not with Ipad but you know what I mean. I am using swift 3 xcode 8.3.3 – user3757894 Sep 07 '17 at 17:46
  • @user3757894 - here is a GitHub repo you can try. Same as the code at that post, but with 4 labels - one at each corner - defining a 2000 x 4000 pt scrollable area. https://github.com/DonMag/LongScroll – DonMag Sep 07 '17 at 18:50
  • @DonMag - Please tell what version of swift and xcode are you using. – user3757894 Sep 13 '17 at 18:37
  • @user3757894 - I've run that from Xcode 8.2 and 8.3 with Swift 3 (and with Obj-C), on simulators and devices. I even put that in a code file with the Swift Playgrounds app. It is basic scroll view features. – DonMag Sep 13 '17 at 18:41
  • @user3757894 - here is some similar code you can try... it creates a scroll view, and adds 41 labels, each 100-pts farther down. This way you can see the numbered labels as you scroll: https://gist.github.com/DonMag/0cebb2f08fde00089e550f0b7c83a37c – DonMag Sep 13 '17 at 19:15
  • @DonMag - I am going to try your code on my macmini at home. I bought the mac 4 years ago while working at another job. I have never opened the box. I am going to set up the box this weekend and run your code as the first program. If it runs properly I will bring my mac to work and build my code with it instead of the one we have. – user3757894 Sep 13 '17 at 20:04

1 Answers1

-2

You can use contentSize of uiscrollview

  • I set the contentSize y value to 4000 and then added a label and anchored it to the bottom with a y value of 3950. The scrollview will not scroll past y=1000. Here is how I know that. When I change the y value of the label to y=1000 I can see the label. I cannot see it at y=3950. – user3757894 Sep 07 '17 at 14:56