开发者

UIPageControl render quirk with UIScrollView

开发者 https://www.devze.com 2022-12-10 18:19 出处:网络
I\'m building an iPhone application and like most I am trying to implement a UIScrollView with a UIPageControl, however I am coming across a very quirky behavior, which I assume may be a bug. Hopefull

I'm building an iPhone application and like most I am trying to implement a UIScrollView with a UIPageControl, however I am coming across a very quirky behavior, which I assume may be a bug. Hopefully one of you has seen this before because it is driving me nuts.

Basically, the page control works fine, everything is hooked up and works normally on all accounts EXCEPT, with certain placements of the UIPageControl within the UIView, the UIPageControl will cease to render.

I'll just take screenshots of the XIB window to help illustrate... here's a placement that works perfectly fine:

http://www.jasconi.us/prob1.png

The UIPageControl is placed physically above the UIScrollView. Works great, everything is visible and working.

The next two DO NOT work:

http://www.jasconi.us/prob2.png http://www.jasconi.us/prob3.png

The first one is simply placed below the scroll view. Doesn't render at all.

The second one is placed above the scroll view without technically being inside of it.开发者_如何学JAVA Also doesn't render.

What the hell is up with this? I've tried using

[[self view] bringSubviewToFront:pageControl];

...to no avail.

Any ideas?


OK I found the answer to this, it's a little six degrees of Kevin Bacon.

This isn't actually a software bug, but a XIB quirk, for some reason the lower placement of the page control in combination with the default settings for autosize and anchor seem to jettison the control into outer space.

If you turn off all auto-scaling and auto-sizing and auto-anchoring and all that other crap, the controls appear exactly as you expected. The fact that it appears reliably when placed above the ScrollView is an oddity.

shrug.

Hope this helps future iPhone initiates.


Did you check to make sure that numberOfPages is not 0?

If you set a breakpoint can you see that pageControl is not nil?


I was still encountering this exact same problem, even after trying everyone's posted answers. My issue ended up being a little more "DOH":

I was using UIPageControl at the bottom of a modal FormSheet, however, I forgot to set the size of the view as Form Sheet in the xib. This caused my page control to be off the screen and never visible.

Moral: set view size (Full, Form, Page, etc) in your xib on the base view.


This will sound like a real no brainer, but I got caught out by it.

By default, UIPageControl expects to be on a dark background. IE: The dots are light gray, and white for the current page.

I used UIPageControl on it's own with no scrollview to change the time range of a graph I was rendering with drawRect:

Long story short, the graph background was white, so the page controller worked, I just couldn't see it. The solution was putting the graph itself in a subview, and making the parent that contained the page control have a dark background.

0

精彩评论

暂无评论...
验证码 换一张
取 消