0

Have a page view controller (orange) which sits on your screen (pink) with a few pages (blue).

Tap run in Xcode ...

enter image description here

Notice that, in fact, it only shows "0" at first. There's a blank space where "1" will later appear.

As soon as you very slightly scroll the pager, "1" is then drawn. The same problem then happens with "2".

What is the straightforward solution to this issue? I've not been able to find a clean fix.

(FTR here's exactly how to do a page controller: https://stackoverflow.com/a/26024779/294884 )

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 1
    In this case maybe just use a collection view with custom flow layout? – aheze Apr 19 '23 at 14:51
  • @aheze , by all means, there are a number of alternatives. note, a very "simple" alternative is just use a scroll view with paging turned on. however, you lose an incredible amount o convenience. in any alternative, you have to treat every single "panel" as a manually, dynamically installed container view. it's not the end of the world, but, certainly incredibly tighter to just use a UIPageViewController :/ – Fattie Apr 19 '23 at 14:57
  • @Fattie - it's not clear what your goal is... Do you want the pages to be **visible** outside the frame of the page view controller? – DonMag Apr 19 '23 at 17:09
  • hi @DonMag so sorry I haven't responded to our other question. I want you to know I've literally been moving around the world on a project (Asia, Americas) since we last spoke! Don, i think it's pretty clear, try it and *"There's a **blank space** where "1" will **later** appear"* As it then says, *[ONLY...] As soon as you **very slightly** scroll the pager, "1" is then drawn. The same problem then happens with "2"* Thus indeed (as you'd expect), in the drawing shown, "1" is certainly visible (there's no clipping). .. cont – Fattie Apr 19 '23 at 19:47
  • .. But (1) simply *is not drawn* apparently "at first" when the screen is loaded. Give it a try. – Fattie Apr 19 '23 at 19:47
  • @Fattie - hmmm... quick test here - not sure I'm the "blank space"? https://imgur.com/a/3WEJTYK – DonMag Apr 19 '23 at 21:29
  • right - simple - my diagram, make the orange (the page vc) say 1/2 the width of the purple ... – Fattie Apr 20 '23 at 01:33
  • @Fattie - do you see your issue with this example? https://pastebin.com/T3QwRLEQ – DonMag Apr 20 '23 at 13:26
  • Cheers @DonMag , (notice my sketch in the Q) this is about and is only about when one is not clipping the pager. As you know to "not clip a pager" you have to unclip the content view of the pageVC. So first, here's the trivial brute force way to do that: https://imgur.com/a/Q1HL0ov . Would you mind, pls add code like that to your example. Click run .. and you'll instantly see the problem. FTR I am building to iPad (as you know, there are a few annoying differences iphone/ipad, so I'm mentioning that so we're on the same "page" hah hah) Run, and you will see the issue instantly. – Fattie Apr 22 '23 at 16:58
  • @Fattie - because of the amount of "under-the-hood" work a `UIPageViewController` does, it's unlikely you'll be able to accomplish that... at least, without burrowing deep into the undocumented features and risking breaking something. Almost certainly easier to build your own (like we did back before collection views and page controllers were a thing). – DonMag Apr 22 '23 at 19:17
  • hi @DonMag yes it's a good point (Indeed - as you can imagine I did just build my own to move along!) ONe thing that occured to me - there's a very similar situatiuon, where, in a table view you do want cells to not-yet-destruct even when they're somewhat outside the table view area - there's a QA on here about it I will dig up. There's a simple solution and, it may be the same. I'll see if I can find it. – Fattie Apr 23 '23 at 14:03
  • @DonMag . I was thinking about this. there must be a call "is a view X at all within a given rect or view" (ie do the rects intersect) In fact that must be how a collection view (or table view) decides if a cell is to be shown. Indeed, is it just part of flow layout (or some cv layout) in some way? Does that come to mind? Maybe it's just a matter of overriding that?? Interesting ! – Fattie Apr 25 '23 at 15:54
  • @Fattie - no... the scroll view in a `UIPageViewController` only ever has 3 subviews. When dragging, it says "which controller view needs to go there?" If that view is *already* there, we're all set. If it is *not* there, put it there. Run my code with your "un-clip" code... adjust the sizing so you *could* see more than 3 pages. Scroll to the 3rd page. Now, start scrolling right-to-left (slowly), as far as you can. You will see the left-most view disappear when the new right-most view appears. – DonMag Apr 25 '23 at 16:07
  • @DonMag yes excellent point. You're quite right that the scroll view has a limited number of subviews. it's just incredible there isn't an easier way to page by cell size than collection veiw width ! :/ – Fattie Apr 25 '23 at 16:30
  • @Fattie - `UIScrollView` can do paging... do you have ***many, many*** "pages"? Or very "heavy" pages, that you would worry about memory usage? – DonMag Apr 25 '23 at 20:52
  • Don - sure, there's plenty of alternatives (see above). UIPageViewController offers advantages. THere's no problem with alternatives - it's long done - I like these arcane curiosities! :) – Fattie Apr 25 '23 at 21:20

0 Answers0